Module: Coerce

Defined in:
lib/coerce.rb

Constant Summary collapse

Version =

version

'0.0.8'
List =
[]

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.[](sym) ⇒ Object

Raises:

  • (ArgumentError)


199
200
201
202
203
204
205
206
207
208
209
# File 'lib/coerce.rb', line 199

def self.[] sym
  prefix = sym.to_s.downcase.to_sym
  candidates = List.select{|m| m =~ %r/^#{ prefix }/i}
  m = candidates.shift
  raise ArgumentError, "unsupported coercion: #{ sym.inspect } (#{ List.join ',' })" unless
    m
  raise ArgumentError, "ambiguous coercion: #{ sym.inspect } (#{ List.join ',' })" unless
    candidates.empty? or m.to_s == sym.to_s
  this = self
  lambda{|obj| method(m).call obj}
end

.coerce(m, &b) ⇒ Object



48
49
50
51
52
# File 'lib/coerce.rb', line 48

def self.coerce m, &b
  define_method m, &b
  export m
  List << m.to_s
end

.dependenciesObject

dependencies



20
21
22
23
24
# File 'lib/coerce.rb', line 20

def self.dependencies
  {
    'chronic'   =>  [ 'chronic'   , '>= 0.6.2' ]
  }
end

.export(m) ⇒ Object



41
42
43
44
# File 'lib/coerce.rb', line 41

def self.export m
  module_function m
  public m
end

.versionObject



14
15
16
# File 'lib/coerce.rb', line 14

def self.version
  Coerce::Version
end

Instance Method Details

#uriObject

built-in



4
# File 'lib/coerce.rb', line 4

require 'uri'