Refinements change only classes, not modules, so the argument must be a class.
- http://ruby-doc.org/core-2.1.1/doc/syntax/refinements_rdoc.html
Once you realize what you are doing, you have two options for refining module methods around the world. Since ruby has public classes, you can simply override the method:
▶ Math.exp 2 #⇒ 7.38905609893065 ▶ module Math ▷ def self.exp arg ▷ Math::E ** arg ▷ end ▷ end #⇒ :exp ▶ Math.exp 2 #⇒ 7.3890560989306495
If you want to keep the functionality of the method for rewriting:
▶ module Math ▷ class << self ▷ alias_method :_____exp, :exp ▷ def exp arg ▷ _____exp arg ▷ end ▷ end ▷ end
Pay attention to side effects.
mudasobwa
source share