module FloatDivision refine Fixnum do def /(other); self.to_f / other; end end end class MathFun using FloatDivision def self.ratio(a, b) a / b end end p MathFun.ratio(6, 8) THE OLD IDEA (no longer works)
module FloatDivision refine Fixnum do def /(other); self.to_f / other; end end end class MathFun using FloatDivision def self.ratio(a, b) a / b end end p MathFun.ratio(6, 8)
module FloatDivision refine Fixnum do def /(other); self.to_f / other; end end end using FloatDivision class MathFun def self.ratio(a, b) a / b end end p MathFun.ratio(6, 8) Main context is OK
module Bar def my_method "inside the module" end end class Foo include Bar def my_method "inside the class" super end end x = Foo.new p x.my_method 1 2
module Bar def my_method "inside the module" super end end class Foo prepend Bar def my_method "inside the class" end end x = Foo.new p x.my_method 1 2
tracer = TracePoint.new do |tp| to_display = [tp.event, File.basename(tp.path), tp.lineno, tp.defined_class, tp.method_id] puts "%10s in %s at line %-2d %s:%s" % to_display end tracer.enable # .. normal code here ..