Module: Metafun::Switchmaker

Included in:
Class
Defined in:
lib/metafun/switchmaker.rb

Instance Method Summary collapse

Instance Method Details

#switch(argument, default = false) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/metafun/switchmaker.rb', line 3

def switch argument, default = false
  class_variable_set :"@@#{argument}", default
  class_eval "    def self.\#{argument}?\n      return @@\#{argument}.call if @@\#{argument}.kind_of? Proc\n      return @@\#{argument}\n    end\n    \n    def self.\#{argument} the_arg\n      if the_arg.kind_of? Proc\n        @@\#{argument} = the_arg\n      else\n        case the_arg\n          when :on;     @@\#{argument} = true\n          when :yes;    @@\#{argument} = true\n          when 1;       @@\#{argument} = true\n          when true;    @@\#{argument} = true\n          when :off;    @@\#{argument} = false\n          when :no;     @@\#{argument} = false\n          when 0;       @@\#{argument} = false\n          when false;   @@\#{argument} = false\n        end\n      end\n    end\n  STRING\nend\n"