Module: Main::Cast
- Defined in:
- lib/main/cast.rb
Constant Summary collapse
- List =
[]
Class Method Summary collapse
Class Method Details
.[](sym) ⇒ Object
141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/main/cast.rb', line 141 def self.[] sym prefix = sym.to_s.downcase.to_sym candidates = List.select{|m| m =~ %r/^#{ prefix }/i} m = candidates.shift raise ArgumentError, "unsupported cast: #{ sym.inspect } (#{ List.join ',' })" unless m raise ArgumentError, "ambiguous cast: #{ sym.inspect } (#{ List.join ',' })" unless candidates.empty? or m.to_s == sym.to_s this = self lambda{|obj| method(m).call obj} end |
.cast(m, &b) ⇒ Object
10 11 12 13 14 |
# File 'lib/main/cast.rb', line 10 def self.cast m, &b define_method m, &b export m List << m.to_s end |
.export(m) ⇒ Object
3 4 5 6 |
# File 'lib/main/cast.rb', line 3 def self.export m module_function m public m end |