J
Jason Lillywhite
Is this the best way (though contrived) to use a hash as an argument in
ruby?
def state_name_age(feeling, info{})
"#{:name} is #{feeling} #{:age} #{:units} old"
end
my_info = {}
my_info = {:name => "Kate", :units => "years", :age => 24}
irb(main):018:0> state_name_age('happily', my_info)
=> "Kate is happily 24 years old"
then...
irb(main):068:0> state_name_age 'happily'
=> " is happily old!"
This seems to be the way Rails has things set up to pass optional
arguments... Is that correct?
ruby?
def state_name_age(feeling, info{})
"#{:name} is #{feeling} #{:age} #{:units} old"
end
my_info = {}
my_info = {:name => "Kate", :units => "years", :age => 24}
irb(main):018:0> state_name_age('happily', my_info)
=> "Kate is happily 24 years old"
then...
irb(main):068:0> state_name_age 'happily'
=> " is happily old!"
This seems to be the way Rails has things set up to pass optional
arguments... Is that correct?