2014 - 12 - 16 Rubyのメソッドの引数にハッシュを渡す Rubyの引数にハッシュを渡す時 {} を省略することができる def profile (hash) p hash end hash = { a : 1 , b : 2 , c : 3 } profile(hash) # {:a=>1, :b=>2, :c=>3} profile({ a : 1 , b : 2 , c : 3 }) # {:a=>1, :b=>2, :c=>3} profile( a : 1 , b : 2 , c : 3 ) # {:a=>1, :b=>2, :c=>3} 例のように先頭に他の引数があり、以降はハッシュなら同じように省略できる。 def profile (str, hash) p str p hash end profile( " Tom " , a : 1 , b : 2 , c
![Rubyのメソッドの引数にハッシュを渡す - 俺はそんなにやる気ない](https://cdn-ak-scissors.b.st-hatena.com/image/square/114277d345e2e8d94085fc8058745c0dbbaaef89/height=288;version=1;width=512/http%3A%2F%2Fcdn.image.st-hatena.com%2Fimage%2Fscale%2F52dbbd09c85bf6c91957d29388e6f2b5927909a4%2Fbackend%3Dimager%3Benlarge%3D0%3Bheight%3D1000%3Bversion%3D1%3Bwidth%3D1200%2Fhttp%253A%252F%252Fcdn.mogile.archive.st-hatena.com%252Fv1%252Fimage%252Ftakkinoue%252F297796840576079783.jpg)