-
Notifications
You must be signed in to change notification settings - Fork 53
Open
Description
The def ===(o) = inside RespondTo (works if you switch it over to an ended method)
seeing_is_believing -ge '
module Types
2.times do
using Types
private def to_type(o) = (Symbol === o ? RespondTo.new(o) : o)
def |(type) = Or.new(to_type(self), to_type(type))
refine(Module) { include Types }
refine(Symbol) { include Types }
end
RespondTo = Struct.new(:name) {
def ===(o) = o.respond_to?(name)
def inspect() = ".respond_to?(#{name.inspect})"
}.include(Types)
Or = Struct.new(:left, :right) {
def ===(o) left === o || right === o end
def inspect() = "(#{left.inspect} | #{right.inspect})"
}.include(Types)
end
using Types
Integer | String | (:to_int | :to_str) # => ' -xMetadata
Metadata
Assignees
Labels
No labels