Skip to content

Instantly share code, notes, and snippets.

@to4iki
Created December 31, 2013 11:19
Show Gist options
  • Save to4iki/8195462 to your computer and use it in GitHub Desktop.
Save to4iki/8195462 to your computer and use it in GitHub Desktop.
Ruby

メソッドの引数にハッシュを渡す

def show(args)                                                 
  name = args[:name]                                           
  say = args[:say]                                             
  p "#{name}, #{say}"                                      
end     
                                                       
show(name: "bam", say: "hello")  #=>"bam,hello"
show(:name => "bam", :say => "goodbye")  #=>"bam,goodbye" 

ハッシュの[ ]を省略できる。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment