Sha256: 8ad67aeaa66a3c17ebee0f363798d677ac059aca078e5ff234bbdf76dad28722

Contents?: true

Size: 403 Bytes

Versions: 15

Compression:

Stored size: 403 Bytes

Contents

require 'myrrha/coerce'

class Foo
  def initialize(arg)
    @arg = arg
  end
end

MyRules = Myrrha::Coerce.dup.append do |r|
  r.coercion(Symbol, Foo) do |value, _|
    Foo.new(value)
  end
end 

begin
  Myrrha::Coerce.apply(:hello, Foo)
  raise "Unexpected"
rescue Myrrha::Error
  # => Myrrha::Error: Unable to coerce `hello` to Foo
end

MyRules.apply(:hello, Foo) 
# =>  #<Foo:0x8b7d254 @arg=:hello>

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
myrrha-3.1.0 examples/coerce_foo3.rb
myrrha-3.0.0 examples/coerce_foo3.rb
myrrha-3.0.0.rc7 examples/coerce_foo3.rb
myrrha-3.0.0.rc6 examples/coerce_foo3.rb
myrrha-3.0.0.rc5 examples/coerce_foo3.rb
myrrha-3.0.0.rc4 examples/coerce_foo3.rb
myrrha-3.0.0.rc3 examples/coerce_foo3.rb
myrrha-3.0.0.rc2 examples/coerce_foo3.rb
myrrha-3.0.0.rc1 examples/coerce_foo3.rb
myrrha-2.0.0 examples/coerce_foo3.rb
myrrha-1.2.2 examples/coerce_foo3.rb
myrrha-1.2.1 examples/coerce_foo3.rb
myrrha-1.2.0 examples/coerce_foo3.rb
myrrha-1.1.0 examples/coerce_foo3.rb
myrrha-1.0.0 examples/coerce_foo3.rb