Skip to content

Instantly share code, notes, and snippets.

@frcake
Last active October 29, 2019 14:18
Show Gist options
  • Save frcake/1d83cd7bd09d9c9c3783939091f15de5 to your computer and use it in GitHub Desktop.
Save frcake/1d83cd7bd09d9c9c3783939091f15de5 to your computer and use it in GitHub Desktop.
proc
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
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