-
-
Save RyanScottLewis/437785 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 | |
def subject(&blk) | |
if block_given? | |
blk.call(@subject) # How do I pass by reference and not by value here? | |
else | |
@subject | |
end | |
end | |
end | |
f = Foo.new | |
p f.subject #=> nil | |
f.subject do |s| | |
p s.object_id | |
s = ['one', 'two', 'three'] | |
s.pop | |
p s #=> ['one', 'two'] | |
end | |
p f.subject #=> nil... want it to be ['one, 'two'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment