Last active
October 29, 2019 14:18
-
-
Save frcake/1d83cd7bd09d9c9c3783939091f15de5 to your computer and use it in GitHub Desktop.
proc
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 A | |
def do_stuff | |
b = ClassB.new(word: 'hello') | |
# does not work | |
needs_block_argument(&b.return_the_block) | |
# does not work either | |
needs_another_block_argument(&b.return_another_block) | |
#does work | |
needs_block_argument(&b.return_the_working_block) | |
end | |
end |
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 B | |
attr_accessor :word | |
def initialize(word:) | |
@word = word | |
end | |
def return_the_block | |
-> { "how can i do stuff with #{@word} here?" } | |
end | |
def return_another_block | |
-> { "I can't do stuff with #{word_binding.eval('w')} here." } | |
end | |
def return_the_working_block | |
w = @word | |
-> { "now can i do stuff with #{w}" } | |
end | |
def word_binding | |
w = @word | |
binding | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment