If the last argument to the method is a non-empty hash literal, you can pass it like this:
def foo(x, y, the_hash)
p the_hash['key2']
end
foo(0, 0, :key1 => 'val1', 'key2' => 42)
instead of the usual way:
foo(0, 0, { :key1 => 'val1', 'key2' => 42 })
{} (def foo(x, y, the_hash = {})), .
, "catch-all" (splat), , :
def foo(p1, *rest)
p rest
end
foo(0)
foo(0, 23, 42)
, ,
def foo(p1, *rest, p2)
p rest
end
foo(0, 100)
foo(0, 100, 23, 42)
splat . - splat .
, &, ( Proc) be nil, . , - yield.
def foo(&p)
p.call
end
foo { puts "hello" }
.
def foo
yield
end
foo { puts "hello" }