Method: Multimethod::ObjectExtension::ClassMethods#multimethod
- Defined in:
- lib/multimethod/core_extensions.rb
#multimethod(body, file = nil, line = nil) ⇒ Object
Installs a new Multimethod Method using the multimethod syntax:
class A
multimethod q{
def foo(x)
...
end
}
multimethod q{
def foo(A x)
end
}
end
Interfaces to Multimethod::Table.instance.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/multimethod/core_extensions.rb', line 30 def multimethod(body, file = nil, line = nil) unless file && line fileline = caller(1)[0] if fileline && md = /^(.*):(\d+)$/.match(fileline) file, line = md[1], md[2].to_i newlines = 0 body.gsub(/\n/s){|x| newlines = newlines + 1} line -= newlines end # $stderr.puts "file = #{file.inspect}, line = #{line.inspect}" end ::Multimethod::Table.instance.install_method(self, body, file, line) end |