Class: Primalize::Single::Primalizer

Inherits:
Object
  • Object
show all
Includes:
Type
Defined in:
lib/primalize/single.rb

Constant Summary

Constants included from Type

Type::DEFAULT_COERCION

Instance Method Summary collapse

Methods included from Type

#coerce

Constructor Details

#initialize(primalizer, &coercion) ⇒ Primalizer

Returns a new instance of Primalizer.



344
345
346
347
348
349
350
351
352
353
354
355
# File 'lib/primalize/single.rb', line 344

def initialize primalizer, &coercion
  @primalizer = primalizer
  @coercion = proc do |obj|
    # FIXME: this is dumb
    begin
      coerced = (coercion || DEFAULT_COERCION).call(obj)
      primalizer.new(coerced).call
    rescue ArgumentError => e
      raise TypeError.new(e)
    end
  end
end

Instance Method Details

#===(value) ⇒ Object



357
358
359
# File 'lib/primalize/single.rb', line 357

def === value
  true
end

#inspectObject



361
362
363
# File 'lib/primalize/single.rb', line 361

def inspect
  "primalize(#{@primalizer.inspect})"
end