Class: Yadriggy::CommonSuperType

Inherits:
Type
  • Object
show all
Defined in:
lib/yadriggy/type.rb

Overview

The most specific common super type. A value of this type is either an instance of ‘self.type` or a subclass of `self.type`.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Type

#!=, #copy, #eql?, error_found!, #exact_type, get_instance_method_object, #has_role?, #is_super_of?, role

Constructor Details

#initialize(t) ⇒ CommonSuperType



243
244
245
# File 'lib/yadriggy/type.rb', line 243

def initialize(t)
  @type = t
end

Instance Attribute Details

#typeModule (readonly)



240
241
242
# File 'lib/yadriggy/type.rb', line 240

def type
  @type
end

Instance Method Details

#<=(t) ⇒ Boolean

Check the subtype relation. or a subtype of ‘t`.



262
263
264
265
266
267
268
269
# File 'lib/yadriggy/type.rb', line 262

def <= (t)
  if t.is_super_of?(self)
    true
  else
    ct = CommonSuperType.role(t)
    !ct.nil? && (@type <= ct.type || @type == NilClass)
  end
end

#==(t) ⇒ Object



248
249
250
# File 'lib/yadriggy/type.rb', line 248

def == (t)
  CommonSuperType.role(t)&.type == @type
end

#get_method_object(method_name) ⇒ Object



272
273
274
# File 'lib/yadriggy/type.rb', line 272

def get_method_object(method_name)
  nil
end

#hashObject



253
254
255
# File 'lib/yadriggy/type.rb', line 253

def hash
  @type.hash + 1
end

#nameString

Obtains the name of this type.



287
288
289
# File 'lib/yadriggy/type.rb', line 287

def name
  @type.name + '+'
end

#supertypeCommonSuperType|nil



277
278
279
280
281
282
283
# File 'lib/yadriggy/type.rb', line 277

def supertype
  if @type.is_a?(Class) && !@type.superclass.nil?
    CommonSuperType.new(@type.superclass)
  else
    nil
  end
end