Class: Stitcher::Type

Inherits:
Object show all
Includes:
TypeOperators
Defined in:
lib/stitcher/type.rb

Instance Method Summary collapse

Methods included from TypeOperators

#!, #&, #+@, #|

Constructor Details

#initialize(klass = nil, &block) ⇒ Type

Returns a new instance of Type.



52
53
54
55
56
57
58
59
60
# File 'lib/stitcher/type.rb', line 52

def initialize klass = nil, &block
  @comp = block
  @comp = lambda do |other, op|
    # change operator "<" to ">".
    return other.comp(klass, op.to_s.tr("<>", "><"))  if other.class == Type
    return self.comp(other, :==) if op.to_sym == :===
    klass.__send__ op, other.classtype
  end unless block_given?
end

Instance Method Details

#comp(other, op) ⇒ Object



62
63
64
# File 'lib/stitcher/type.rb', line 62

def comp other, op
  !!@comp.(other, op)
end

#typeObject



72
73
74
# File 'lib/stitcher/type.rb', line 72

def type
  self
end