Created
January 7, 2011 01:35
-
-
Save abscondment/768965 to your computer and use it in GitHub Desktop.
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 | |
attr_accessor :bar | |
def initialize | |
@bar = 'init' | |
end | |
def fun | |
lambda { "got: #{@bar}" } | |
end | |
def fun2 | |
b = @bar | |
lambda { "got: #{b}" } | |
end | |
end | |
def try_me(fn) | |
fn.call | |
end | |
foo = Foo.new | |
puts try_me(foo.fun) | |
puts try_me(foo.fun2) | |
fn = foo.fun | |
foo.bar = 'newbar' | |
puts fn.call | |
puts try_me(fn) | |
puts try_me(foo.fun) | |
puts try_me(foo.fun2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment