Created
March 9, 2013 23:59
-
-
Save sumanmukherjee03/5126400 to your computer and use it in GitHub Desktop.
Does implicit return in ruby violate encapsulation?
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 Outer | |
class Inner | |
def initialize(attrs) | |
@obj = attrs | |
end | |
def do_something | |
# do somehting with the @obj | |
@obj | |
end | |
end | |
def do_something | |
x = Inner.new(:foo => 'bar') | |
x.do_something | |
end | |
end | |
o1 = Outer.new | |
i1 = o1.do_something | |
i1.delete(:foo) # dangerous. Probably could have been avoided if Outer#do_something returned self at the end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment