Skip to content

Instantly share code, notes, and snippets.

@marcroberts
Last active December 17, 2015 22:49
Show Gist options
  • Select an option

  • Save marcroberts/5684667 to your computer and use it in GitHub Desktop.

Select an option

Save marcroberts/5684667 to your computer and use it in GitHub Desktop.
Private methods in ruby aren't that private
class Thing
private
def some_private_method number
print "Success (#{number})\n\n"
end
end
thing = Thing.new
print "Calling thing.some_private_method: "
begin
thing.some_private_method 12345
rescue
print "FAILED\n\n"
end
print "Calling thing.some_private_method via send: "
thing.send :some_private_method, 12345
$ ruby private.rb
Calling thing.some_private_method: FAILED
Calling thing.some_private_method via send: Success (12345)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment