ANN: Matchable 0.2

The Matchable mixin borrows ideas from ML
probably other functional languages).
The syntax currently supported looks like this:

class Bar
include Matchable
def_match(:plus, nil, nil){|a,b| a+b}
def_match(:plus, String, nil){|a,b| “#{a}:=>#{b}”}
def_match(:plus, /hello/, nil){|a, b| “hello world”}

b =
=> #Bar:0xb758e7ac,5)
=> 10“five”,5)
=> “five:=>5”“hello”, 5)
=> “hello world”

class Foo
include Matchable
def test(tuple)
case tuple
when mcase([:test, 5, 5]) then “poop”
when mcase([:test, nil, nil]) then “whoop”
when mcase([nil, nil]) then “hoot”
else “foot”

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs