how do you assign a default argument?
def repeat(message, num=1)
message * num
end
p repeat("hi") # => "hi"
p repeat("hi", 3) # => "hihihi"If you have a method that accepts a hash as an argument can you omit the braces when passing in the hash?
yes you can
def modify_string(str, options)
str.upcase! if options["upper"]
p str * options["repeats"]
end
# less readable
modify_string("bye", {"upper"=>true, "repeats"=>3}) # => "BYEBYEBYE"
# more readable
modify_string("bye", "upper"=>true, "repeats"=>3) # => "BYEBYEBYE"