def greet(name)
yield name
end
greet('calling a block using yield') { |x| puts x }
def greet(name, &block)
block.call(name)
end
greet('calling a &block using block.call') { |x| puts x }
def greet(name, proc)
proc.call(name)
end
greet('passing a proc', proc { |x| puts x })
greet('passing a lambda', lambda { |x| puts x })
greet('passing a -> (lambda shorhand)', -> (x) { puts x })
To embed this project on your website, copy the following code and paste it into your website's HTML: