Created
February 9, 2015 18:10
-
-
Save teeparham/5400ffffa5109fa6a907 to your computer and use it in GitHub Desktop.
Why you should use implicit self in ruby
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 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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Isn't by design?