Ampersand at the end of the method signature will capture and expect a block for you.
def foo(bar, &block)
block.call (bar += 1)
end
Ampersand can also be used in this form to call to_procand let you call a method :addresswith a symbol (example borrowed from another place)
@webs ||= Web.find(:all).index_by &:address
Shortcuts such as +=and -=are convenient.
Not a statement, but another Rails shortcut makes it possible. This will give you a bar when foo - nil?orfalse
a = foo || bar
In terms of “operators”, I found here a (unofficial) thing for reference: Ruby operators
source
share