From dbb55f88451d27c4343da544e2a6577897bd7bd8 Mon Sep 17 00:00:00 2001 From: Nat Lasseter Date: Fri, 16 Feb 2018 16:33:10 +0000 Subject: Making things much worse but functions are now callable --- patter.rb | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'patter.rb') 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 -- cgit v1.2.1