Project

General

Profile

Bug #14459 » test.rb

jnchito (Junichi Ito), 02/09/2018 12:18 AM

 
h = { us: 'dollar', india: 'rupee' }
# 変数hのキーと値を**で展開させる
{ japan: 'yen', **h } #=> {:japan=>"yen", :us=>"dollar", :india=>"rupee"}

# **を付けない場合は構文エラーになる
# { japan: 'yen', h }
#=> SyntaxError: syntax error, unexpected '}', expecting =>
# { japan: 'yen', h }
# ^

# ----------------------------------------

h = { us: 'dollar', india: 'rupee' }
{ japan: 'yen' }.merge(h) #=> {:japan=>"yen", :us=>"dollar", :india=>"rupee"}
    (1-1/1)