views:

31

answers:

1

How do I override methods in a module?

+1  A: 

Just put your new method in later on in the code. For example, if this is the module (somefile.rb):

module M
  def some_method
    # ...
  end

  def get_time
    time = Time.new
    return time
  end
end

Put this in the file that needs the module:

require "some_module"

module M
  def get_time
    time = Time.parse("07/09/10 21:22")
    return time
  end
end
Adrian
will this work for overriding method in a class?
Mo
@Mo: Yes. And this extra sentence is to pad the comment with content so stack overflow doesn't get mad about a short comment.
Adrian