Sha256: 796f11fe5abe08f8b7835acc3529a0c7fe4a3f5a24772d92fbc4ef14d3dc68d0
Contents?: true
Size: 1001 Bytes
Versions: 1
Compression:
Stored size: 1001 Bytes
Contents
module Domain module FakeDomain def self.new(super_domain, sub_domains, predicate) Module.new{ include Domain, Methods define_method(:super_domain){ super_domain } define_method(:sub_domains) { sub_domains } define_method(:predicate) { predicate } } end module Methods # Creates a new instance of this domain def new(*args) if (args.size == 1) && self===args.first return args.first elsif superclass.respond_to?(:new) && (superclass != Object) return new super(*args) end args_error_on_new(args) end # Checks if `value` belongs to this domain def ===(value) value.is_a?(superclass) && predicate && predicate.call(value) end private def args_error_on_new(args) raise ArgumentError, "Invalid value #{args.join(' ')} for #{self}", caller end end # module Methods end # module FakeDomain end # module Domain
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
domain-1.0.0.rc1 | lib/domain/support/fake_domain.rb |