aboutsummaryrefslogtreecommitdiff
path: root/patter.rb
diff options
context:
space:
mode:
Diffstat (limited to 'patter.rb')
-rw-r--r--patter.rb14
1 files changed, 13 insertions, 1 deletions
diff --git a/patter.rb b/patter.rb
index 348cbdf..282af46 100644
--- a/patter.rb
+++ b/patter.rb
@@ -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