Ruby parameters code example
Example 1: ruby name parameters
def foo(bar: 'default')
puts bar
end
foo
foo(bar: 'baz')
Example 2: ruby named parameters
def show_name_and_address(name: "Someone", address: "Somewhere")
puts "#{name}, #{address}"
end
show_name_and_address
show_name_and_address(name: 'Andy')
show_name_and_address(address: 'USA')
Example 3: ruby named parameters
def show_name_and_address(name="Someone", address="Somewhere")
puts "#{name}, #{address}"
end
show_name_and_address
show_name_and_address('Andy')