Skip to content

Instantly share code, notes, and snippets.

@myronmarston
Last active December 29, 2015 03:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save myronmarston/7609059 to your computer and use it in GitHub Desktop.
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.
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
➜ 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