Convert all system command to all class method : method_missing « Reflection « Ruby






Convert all system command to all class method


class CommandWrapper

  def method_missing(method, *args)
    system(method.to_s, *args)
  end

end


cw = CommandWrapper.new
cw.date                   # Sat Apr 28 22:50:11 CDT 2001
cw.du '-s', '/tmp'        # 166749  /tmp

 








Related examples in the same category

1.Responding to Calls to Undefined Methods
2.Override method_missing method to provide meaningful error message
3.Create a new class and override the method_missing method
4.If method does not exist, call the default one
5.Create new method dynamically