diff options
Diffstat (limited to 'patter.rb')
-rw-r--r-- | patter.rb | 14 |
1 files changed, 13 insertions, 1 deletions
@@ -2,8 +2,14 @@ module Patter class Var; end class Fun - def initialize + def self.find(name) + return $patter_funs[name] + end + + def initialize(name) + $patter_funs = {} unless $patter_funs @patterns = {} + $patter_funs[name] = self end def when(*args, &block) @@ -40,4 +46,10 @@ module Patter raise "Inexhaustive patterns" end end + + def method_missing(name, *args) + if $patter_funs && $patter_funs.include?(name) then + $patter_funs[name].call(*args) + end + end end |