Skip to content

Instantly share code, notes, and snippets.

@teeparham
Created February 9, 2015 18:10
Show Gist options
  • Select an option

  • Save teeparham/5400ffffa5109fa6a907 to your computer and use it in GitHub Desktop.

Select an option

Save teeparham/5400ffffa5109fa6a907 to your computer and use it in GitHub Desktop.
Why you should use implicit self in ruby
class X
# implicit self
def get
value
end
# explicit self does not work when you call a private method
def get_self
self.value
end
private
def value
42
end
end
X.new.get
# => 42
X.new.get_self
# => NoMethodError: private method `value' called for #<X:0x007f99532f0758>
@augnustin

Copy link
Copy Markdown

Isn't by design?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment