Class: Object
- Inherits:
- BasicObject
- Defined in:
- lib/union_type/core_ext.rb
Instance Method Summary collapse
- #__instance_of__? ⇒ Object
- #__is_a__? ⇒ Object
-
#instance_of?(type) ⇒ Boolean
Returns
trueif this object’s exact class is one of the union’s members. -
#is_a?(type) ⇒ Boolean
(also: #kind_of?)
Returns
trueif this object is an instance of any class in the union.
Instance Method Details
#__instance_of__? ⇒ Object
26 |
# File 'lib/union_type/core_ext.rb', line 26 alias_method :__instance_of__?, :instance_of? |
#__is_a__? ⇒ Object
25 |
# File 'lib/union_type/core_ext.rb', line 25 alias_method :__is_a__?, :is_a? |
#instance_of?(type) ⇒ Boolean
53 54 55 |
# File 'lib/union_type/core_ext.rb', line 53 def instance_of?(type) type.__is_a__?(UnionType) ? type.include?(self.class) : __instance_of__?(type) end |
#is_a?(type) ⇒ Boolean Also known as: kind_of?
Returns true if this object is an instance of any class in the union. Falls back to the standard is_a? for plain Class or Module arguments.
38 39 40 |
# File 'lib/union_type/core_ext.rb', line 38 def is_a?(type) type.__is_a__?(UnionType) ? type === self : __is_a__?(type) end |