Created
October 29, 2014 14:06
-
-
Save luislee818/902f2fb18fd2efe068c5 to your computer and use it in GitHub Desktop.
Pass method as argument in Ruby
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Foo | |
def foo | |
r = helper method(:bar) | |
# r = helper Proc.new { bar } | |
puts r | |
end | |
def bar | |
3 | |
end | |
end | |
def helper(fn) | |
fn.call | |
end | |
f = Foo.new | |
f.foo # 3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment