Sha256: 8f2ccc515947f2ebc15132ecd214c26c6d8f1b4b8610656bf907269cde729804

Contents?: true

Size: 653 Bytes

Versions: 8

Compression:

Stored size: 653 Bytes

Contents

require 'myrrha'

PosInt = Domain.sbyc(Integer){|i| i>0}

###
  
PosInt.class
PosInt.superclass
PosInt.ancestors
PosInt === 10
PosInt === -1
PosInt.new(10)
begin
  PosInt.new(-10)
  raise "Unexpected case: PosInt.new(-10) succeeds"
rescue TypeError => ex
  puts ex.message
end

###

10.is_a?(PosInt)
10.kind_of?(PosInt)

###

rules = Myrrha.coercions do |r|
  r.coercion String, Integer, lambda{|s,t| Integer(s)}  
end 
rules.coerce("12", Integer)
rules.coerce("12", PosInt)
rules.coerce("-12", Integer)
begin
  rules.coerce("-12", PosInt)
  raise "Unexpected case: rules.coerce('-12', PosInt) succeeds"
rescue Myrrha::Error => ex
  puts ex.message
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
myrrha-3.1.0 examples/sbyc_domain.rb
myrrha-3.0.0 examples/sbyc_domain.rb
myrrha-3.0.0.rc7 examples/sbyc_domain.rb
myrrha-3.0.0.rc6 examples/sbyc_domain.rb
myrrha-3.0.0.rc5 examples/sbyc_domain.rb
myrrha-3.0.0.rc4 examples/sbyc_domain.rb
myrrha-3.0.0.rc3 examples/sbyc_domain.rb
myrrha-3.0.0.rc2 examples/sbyc_domain.rb