Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save sumanmukherjee03/5126400 to your computer and use it in GitHub Desktop.
Save sumanmukherjee03/5126400 to your computer and use it in GitHub Desktop.
Does implicit return in ruby violate encapsulation?
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