Created
February 19, 2013 00:13
-
-
Save pragdave/4981930 to your computer and use it in GitHub Desktop.
The Ruby 2 prepend() method makes method chaining a lot easier.
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
module SystemHook | |
private | |
def system(*args) | |
super.tap do |result| | |
puts "system(#{args.join(', ')}) returned #{result.inspect}" | |
end | |
end | |
end | |
class Object | |
prepend SystemHook | |
end | |
system("date") | |
system("kangaroo", "-hop 10", "skippy") |
@RogueValley In Ruby, a private method is defined as a method which can't be called with the explicit receiver but only with omitted self
.
So system(...)
can call even a private method.
Is there are any ability to access an old system
method?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How are you calling a private method? Is is because we are inside main, which is an instance of Object?