class Argtrace::Type
type in RBS manner
Attributes
data[RW]
subdata[RW]
Public Class Methods
new()
click to toggle source
# File lib/argtrace/signature.rb, line 136 def initialize() @data = nil @subdata = nil end
new_with_type(actual_type)
click to toggle source
# File lib/argtrace/signature.rb, line 141 def self.new_with_type(actual_type) ret = Type.new if actual_type == TrueClass || actual_type == FalseClass ret.data = BooleanClass else ret.data = actual_type end return ret end
new_with_value(actual_value)
click to toggle source
# File lib/argtrace/signature.rb, line 151 def self.new_with_value(actual_value) ret = Type.new if actual_value.is_a?(Symbol) # use symbol as type ret.data = actual_value elsif true == actual_value || false == actual_value # warn: operands of == must in this order, because of override. # treat true and false as boolean ret.data = BooleanClass elsif actual_value.class == Array # TODO: multi type array ret.data = Array unless actual_value.empty? if true == actual_value.first || false == actual_value.first ret.subdata = BooleanClass else ret.subdata = actual_value.first.class end end else ret.data = actual_value.class end return ret end
Public Instance Methods
==(other)
click to toggle source
# File lib/argtrace/signature.rb, line 180 def ==(other) if other.class != Type return false end return @data == other.data && @subdata == other.subdata end
eql?(other)
click to toggle source
# File lib/argtrace/signature.rb, line 187 def eql?(other) self.==(other) end
hash()
click to toggle source
# File lib/argtrace/signature.rb, line 176 def hash @data.hash end
inspect()
click to toggle source
# File lib/argtrace/signature.rb, line 234 def inspect to_s end
superclass_of?(other)
click to toggle source
true if self(Type
) includes other(Type
) as type declaration false if self and other is same Type
.
# File lib/argtrace/signature.rb, line 193 def superclass_of?(other) if other.class != Type raise TypeError, "parameter must be Argtrace::Type" end if @data.is_a?(Symbol) return false elsif other.data.is_a?(Symbol) return false elsif @data == Array && other.data == Array # TODO: merge for Array type like: # Array[X] | Array[Y] => Array[X|Y] if @subdata if other.subdata return other.subdata < @subdata else return true end else # if self Array is untyped, cannot replace other as declaration. return false end else # both data should be Class, just compare them return other.data < @data end end
to_s()
click to toggle source
# File lib/argtrace/signature.rb, line 220 def to_s if @data.is_a?(Symbol) @data.inspect elsif @data == Array if @subdata "Array[#{@subdata}]" else @data end else @data.to_s end end