Class: Yadriggy::InstanceType
Overview
Type of a particular Ruby object.
Instance Attribute Summary collapse
-
#object ⇒ Object
readonly
The Ruby object.
Instance Method Summary collapse
-
#<=(t) ⇒ Boolean
Check the subtype relation.
- #==(t) ⇒ Object
-
#exact_type ⇒ Object
Recall that ‘1.class` was `Fixnum` in Ruby earlier than 2.4.
- #get_method_object(method_name) ⇒ Object
- #hash ⇒ Object
-
#initialize(obj) ⇒ InstanceType
constructor
A new instance of InstanceType.
-
#name ⇒ String
Obtains the name of this type.
-
#supertype ⇒ RubyClass
The RubyClass for this class.
Methods inherited from Type
#!=, #copy, #eql?, error_found!, get_instance_method_object, #has_role?, #is_super_of?, role
Constructor Details
#initialize(obj) ⇒ InstanceType
Returns a new instance of InstanceType.
416 417 418 |
# File 'lib/yadriggy/type.rb', line 416 def initialize(obj) @object = obj end |
Instance Attribute Details
#object ⇒ Object (readonly)
Returns the Ruby object.
414 415 416 |
# File 'lib/yadriggy/type.rb', line 414 def object @object end |
Instance Method Details
#<=(t) ⇒ Boolean
Check the subtype relation.
435 436 437 438 439 440 441 442 443 |
# File 'lib/yadriggy/type.rb', line 435 def <= (t) if t.is_super_of?(self) true else it = InstanceType.role(t) (!it.nil? && it.object == @object) || RubyClass[exact_type] <= t end end |
#==(t) ⇒ Object
421 422 423 |
# File 'lib/yadriggy/type.rb', line 421 def == (t) InstanceType.role(t)&.object == @object end |
#exact_type ⇒ Object
Recall that ‘1.class` was `Fixnum` in Ruby earlier than 2.4.
447 448 449 |
# File 'lib/yadriggy/type.rb', line 447 def exact_type @object.is_a?(Integer) ? Integer : @object.class end |
#get_method_object(method_name) ⇒ Object
452 453 454 455 456 |
# File 'lib/yadriggy/type.rb', line 452 def get_method_object(method_name) @object.method(method_name) rescue NameError Type.error_found!("no such method: #{@object.class}\##{method_name}") end |
#hash ⇒ Object
426 427 428 |
# File 'lib/yadriggy/type.rb', line 426 def hash @object.hash end |
#name ⇒ String
Obtains the name of this type.
465 466 467 |
# File 'lib/yadriggy/type.rb', line 465 def name @object.to_s end |