abstract class Class
inherits Value
¶
Class methods¶
.<(other : T.class) : Bool forall T
¶
(other : T.class) : Bool forall T
Returns whether this class inherits or includes other.
Int32 < Number # => true
Int32 < Value # => true
Int32 < Int32 # => false
Int32 <= String # => false
.<=(other : T.class) : Bool forall T
¶
(other : T.class) : Bool forall T
Returns whether this class inherits or includes other, or is equal to other.
Int32 < Number # => true
Int32 < Value # => true
Int32 <= Int32 # => true
Int32 <= String # => false
.==(other : Class) : Bool
¶
(other : Class) : Bool
Returns whether this class is the same as other.
Int32 == Int32 # => true
Int32 == String # => false
.===(other)
¶
(other)
Case equality.
The ===
method is used in a case ... when ... end
expression.
For example, this code:
case value
when x
# something when x
when y
# something when y
end
Is equivalent to this code:
if x === value
# something when x
elsif y === value
# something when y
end
Object simply implements ===
by invoking ==
, but subclasses
(notably Regex
) can override it to provide meaningful case-equality semantics.
.>(other : T.class) forall T
¶
(other : T.class) forall T
Returns whether other inherits or includes self
.
Number > Int32 # => true
Number > Number # => false
Number > Object # => false
.>=(other : T.class) forall T
¶
(other : T.class) forall T
Returns whether other inherits or includes self
, or is equal
to self
.
Number >= Int32 # => true
Number >= Number # => true
Number >= Object # => false
.dup
¶
Returns a shallow copy of this object.
Because Value
is a value type, this method returns self
,
which already involves a shallow copy of this object because
value types are passed by value.
.inspect(io : IO) : Nil
¶
(io : IO) : Nil
Appends a string representation of this object
to the given IO
object.
Similar to to_s(io)
, but usually appends more information
about this object.
See #inspect
.
.nilable?
¶
Returns true
if this class is Nil
.
Int32.nilable? # => false
Nil.nilable? # => true
.to_s(io : IO) : Nil
¶
(io : IO) : Nil
Appends a String
representation of this object
to the given IO
object.
An object must never append itself to the io argument,
as this will in turn call to_s(io)
on it.
.|(other : U.class) forall U
¶
(other : U.class) forall U
Returns the union type of self
and other.
Int32 | Char # => (Int32 | Char)
.cast(other) : self
¶
(other) : self
Casts other to this class.
This is the same as using as
, but allows the class to be passed around as
an argument. See the
documentation on as
for more information.
klass = Int32
number = [99, "str"][0]
typeof(number) # => (String | Int32)
typeof(klass.cast(number)) # => Int32
Methods¶
#<(other : T.class) : Bool forall T
¶
(other : T.class) : Bool forall T
Returns whether this class inherits or includes other.
Int32 < Number # => true
Int32 < Value # => true
Int32 < Int32 # => false
Int32 <= String # => false
#<=(other : T.class) : Bool forall T
¶
(other : T.class) : Bool forall T
Returns whether this class inherits or includes other, or is equal to other.
Int32 < Number # => true
Int32 < Value # => true
Int32 <= Int32 # => true
Int32 <= String # => false
#==(other : Class) : Bool
¶
(other : Class) : Bool
Returns whether this class is the same as other.
Int32 == Int32 # => true
Int32 == String # => false
#===(other)
¶
(other)
Case equality.
The ===
method is used in a case ... when ... end
expression.
For example, this code:
case value
when x
# something when x
when y
# something when y
end
Is equivalent to this code:
if x === value
# something when x
elsif y === value
# something when y
end
Object simply implements ===
by invoking ==
, but subclasses
(notably Regex
) can override it to provide meaningful case-equality semantics.
#>(other : T.class) forall T
¶
(other : T.class) forall T
Returns whether other inherits or includes self
.
Number > Int32 # => true
Number > Number # => false
Number > Object # => false
#>=(other : T.class) forall T
¶
(other : T.class) forall T
Returns whether other inherits or includes self
, or is equal
to self
.
Number >= Int32 # => true
Number >= Number # => true
Number >= Object # => false
#cast(other) : self
¶
(other) : self
Casts other to this class.
This is the same as using as
, but allows the class to be passed around as
an argument. See the
documentation on as
for more information.
klass = Int32
number = [99, "str"][0]
typeof(number) # => (String | Int32)
typeof(klass.cast(number)) # => Int32
#dup
¶
Returns a shallow copy of this object.
Because Value
is a value type, this method returns self
,
which already involves a shallow copy of this object because
value types are passed by value.
#inspect(io : IO) : Nil
¶
(io : IO) : Nil
Appends a string representation of this object
to the given IO
object.
Similar to to_s(io)
, but usually appends more information
about this object.
See #inspect
.
#nilable?
¶
Returns true
if this class is Nil
.
Int32.nilable? # => false
Nil.nilable? # => true
#to_s(io : IO) : Nil
¶
(io : IO) : Nil
Appends a String
representation of this object
to the given IO
object.
An object must never append itself to the io argument,
as this will in turn call to_s(io)
on it.
#|(other : U.class) forall U
¶
(other : U.class) forall U
Returns the union type of self
and other.
Int32 | Char # => (Int32 | Char)