Module: Multimethod

Defined in:
lib/multimethod.rb,
lib/multimethod/table.rb,
lib/multimethod/method.rb,
lib/multimethod/parameter.rb,
lib/multimethod/signature.rb,
lib/multimethod/multimethod.rb,
lib/multimethod/core_extensions.rb,
lib/multimethod/multimethod_version.rb

Overview

Introduction

The Multimethod package implements dispatch of messages to multiple methods based on argument types.

Variadic methods and default values are supported.

Methods can be added and removed at run-time.

Examples

require 'multimethod'

class A
  multimethod %q{
  def foo(x) # matches any argument type
     "#{x.inspect}"
  end
  }

  multimethod %q{
  def foo(Fixnum x) # matches any Fixnum
     "Fixnum #{x.inspect}"
  end
  }

  multimethod %q{
  def foo(Numeric x) # matches any Numeric
     "Numeric #{x.inspect}"
  end
  }
end

a = A.new
puts a.foo(:symbol) # ==> ":symbol"
puts a.foo(45)      # ==> "Fixnum 45"
puts a.foo(12.34)   # ==> "Numeric 12.34"

Known Issues

This library is not yet thread-safe, due to caching mechanisms used to increase performance. This will be fixed in a future release.

Home page

Credits

Multimethod was developed by:

  • Kurt Stephens – ruby-multimethod(at)umleta.com, sponsored by umleta.com

Contributors

Maybe you?

See Also

Defined Under Namespace

Modules: ObjectExtension Classes: Method, Multimethod, Parameter, Signature, Table

Constant Summary collapse

MultimethodVersion =

See: rake update_version

'0.2.0'