# Ruby의 'Hash'는 만능도구 입니다

> Clean Markdown view of GeekNews topic #10499. Use the original source for factual precision when an external source URL is present.

## Metadata

- GeekNews HTML: [https://news.hada.io/topic?id=10499](https://news.hada.io/topic?id=10499)
- GeekNews Markdown: [https://news.hada.io/topic/10499.md](https://news.hada.io/topic/10499.md)
- Type: news
- Author: [xguru](https://news.hada.io/@xguru)
- Published: 2023-08-23T10:33:01+09:00
- Updated: 2023-08-23T10:33:01+09:00
- Original source: [akshaykhot.com](https://www.akshaykhot.com/ruby-hash-is-a-swiss-army-knife/)
- Points: 6
- Comments: 9

## Topic Body

- Ruby의 Hash는 키에 값을 매핑하는 내장 데이터 구조. O(1)  
- 다른 언어들은 키/밸류를 관리하는 클래스가 많지만, 루비는 Hash 클래스 하나로 키/밸류 쌍을 관리   
- 매우 유연한 자료구조로, 데이터 객체 / 딕셔너리 / 해시테이블 / 정렬 리스트 등 외에도 다양하게 사용 가능   
- 심볼/문자열/정수를 포함한 거의 모든 객체를 키로 사용 가능   
- fetch 메소드로 키가 없는 경우 기본값 설정 가능   
- delete 로 키 삭제 가능. 없는 키를 호출해도 문제 없음   
- Nesting 가능   
- 해당 키가 없다면 nil 을 리턴하지만, default 속성으로 기본값 지정 가능   
- Enumerable 모듈을 포함하여 each, each_key, each_pair, each_value, keys, values 등의 메소드로 해시를 이터레이션 가능   
- 더블 Splat 연산자 "**" 로 해시안의 내용을 언팩 가능  
- 그외 유용한 메소드들 : any?(key), compact, empty?, merge, hash.eql? obj, except(*keys), reject, filter & select, fetch_values(*keys), has_key?, member?, include?, key?, has_value?, value?, length, size, count, slice(*keys), transform_values, flatten

## Comments



### Comment 18525

- Author: joyfui
- Created: 2023-08-23T11:43:04+09:00
- Points: 1

대학교에서 c 배우고 파이썬 리스트를 처음 접했을 때의 감동이 떠오르는 군요.

### Comment 18513

- Author: xguru
- Created: 2023-08-23T10:34:02+09:00
- Points: 3

"스위스 아미 나이프" 를  "맥가이버칼" 이라고 번역하려다 요즘 사람들은 못알아들을듯 해서 "만능도구" 로..

### Comment 18628

- Author: roxie
- Created: 2023-08-27T00:05:04+09:00
- Points: 1
- Parent comment: 18513
- Depth: 1

맥가이버까지는 ok인것 같고, 스위스아미나이프는 못들어봤으면 어려울 것 같아요ㅋㅋ

### Comment 18527

- Author: pribess
- Created: 2023-08-23T11:55:31+09:00
- Points: 1
- Parent comment: 18513
- Depth: 1

10대인 저도 이해했습니다 모르는 사람은 별로 없는것 같아요

### Comment 18528

- Author: xguru
- Created: 2023-08-23T12:22:29+09:00
- Points: 1
- Parent comment: 18527
- Depth: 2

헉 놀라운 발견이네요. 전 정말 모를거라 생각했어요.   
그나저나 긱뉴스 사용자 중에 10대도 계셨군요.. 멋지십니다!

### Comment 18589

- Author: antegral
- Created: 2023-08-24T20:42:13+09:00
- Points: 1
- Parent comment: 18528
- Depth: 3

의외로 10대 개발자도 늘고 있어서, 긱뉴스를 접하는 학생 개발자분들이 점차 늘어나는 것 같습니다.  
저도 불과 9달전만 해도 10대였으니까요...

### Comment 18532

- Author: depth221
- Created: 2023-08-23T14:25:35+09:00
- Points: 1
- Parent comment: 18528
- Depth: 3

'맥가이버'라는 드라마가 있었다는 사실을 모르는 사람은 많지만, 그래도 '맥가이버칼'이라는 단어는 다들 알아먹는 것 같습니다.

### Comment 18519

- Author: annyeong
- Created: 2023-08-23T11:10:43+09:00
- Points: 1
- Parent comment: 18513
- Depth: 1

이제는 속담 같은 지위라 괜찮지 않을까요? 일단 20대인 저는 이해했습니다 :D

### Comment 18514

- Author: eususu
- Created: 2023-08-23T10:41:38+09:00
- Points: 1
- Parent comment: 18513
- Depth: 1

아. 이해하면 아재 인증이네요 :)
