Skip to content

Instantly share code, notes, and snippets.

@pragdave
Created February 19, 2013 00:13
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pragdave/4981930 to your computer and use it in GitHub Desktop.
Save pragdave/4981930 to your computer and use it in GitHub Desktop.
The Ruby 2 prepend() method makes method chaining a lot easier.
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")
@roberthead
Copy link

How are you calling a private method? Is is because we are inside main, which is an instance of Object?

@nobu
Copy link

nobu commented Feb 19, 2013

@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.

@dmitry
Copy link

dmitry commented Feb 28, 2013

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