Ruby2018. 1. 17. 19:38

인터액티브 루비(irb) 예제  

hash

 => {"a"=>["b", "c", "d"], "e"=>["f", "g"]}


array = hash.to_a

 => [["a", ["b", "c", "d"]], ["e", ["f", "g"]]]

Hash 를 Array 로 변환

hash2 = array.to_h

 => {"a"=>["b", "c", "d"], "e"=>["f", "g"]}

Array 를 Hash 로 변환

hash <=> hash2

 => 0

hash 와 hash2 는 동일함(0)

<=>는 spaceship operator

 

 

hash.values 를 사용하면 값만 출력됨. 

 [["b", "c", "d"], ["f", "g"]]



반응형

'Ruby' 카테고리의 다른 글

ridk DevKit(Windows) 설치 실패(GPGME error)  (0) 2018.02.06
mixin sample  (0) 2018.01.18
Posted by Jay Two