Last active
December 29, 2015 03:39
-
-
Save myronmarston/7609059 to your computer and use it in GitHub Desktop.
There are some pretty bizarre things you can do with `method_missing` and public/private. But don't.
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 call_private_bar | |
bar | |
end | |
private | |
def bar | |
:private_bar | |
end | |
def method_missing(name, *args) | |
return :public_bar if name == :bar | |
super | |
end | |
end | |
foo = Foo.new | |
puts foo.bar # => :public_bar | |
puts foo.call_private_bar # => :private_bar | |
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
➜ ruby foo.rb | |
public_bar | |
private_bar |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment