Skip to content

Instantly share code, notes, and snippets.

@pragdave
Created February 19, 2013 00:13
Show Gist options
  • Select an option

  • Save pragdave/4981930 to your computer and use it in GitHub Desktop.

Select an option

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
Copy Markdown

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

@nobu

nobu commented Feb 19, 2013

Copy link
Copy Markdown

@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

dmitry commented Feb 28, 2013

Copy link
Copy Markdown

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