Last active
August 29, 2015 13:56
-
-
Save rewinfrey/9096272 to your computer and use it in GitHub Desktop.
Determining if the closure of a lambda referencing an ivar is defined at time of creation, or time of calling.
This file contains 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 Creator | |
def initialize(input1) | |
@input1 = input1 | |
end | |
def create_lambda | |
->() { | |
puts @input1 | |
} | |
end | |
end | |
class Caller | |
def initialize(input1, creator) | |
@input1 = input1 | |
@creator = creator | |
end | |
def call_lambda | |
@creator.create_lambda.call | |
end | |
end | |
creator = Creator.new("creator input") | |
caller = Caller.new("caller input", creator) | |
caller.call_lambda | |
# >> creator input |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment