module Main::Cast

Constants

List

Public Class Methods

[](sym) click to toggle source
# File lib/main/cast.rb, line 141
def self.[] sym
  prefix = sym.to_s.downcase.to_sym
  candidates = List.select{|m| m =~ /^#{ prefix }/}
  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) click to toggle source
# 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) click to toggle source
# File lib/main/cast.rb, line 3
def self.export m
  module_function m
  public m
end