abstract class Class
Defined in:
class.crprimitives.cr
Constructors
-
.cast(other) : self
Castsother to this class.
Class Method Summary
-
.<(other : T.class) : Bool forall T
Returns whether this class inherits or includesother.
-
.<=(other : T.class) : Bool forall T
Returns whether this class inherits or includesother, or is equal toother.
-
.==(other : Class) : Bool
Returns whether this class is the same asother.
-
.===(other)
Case equality.
-
.>(other : T.class) : Bool forall T
Returns whetherother inherits or includes
self. -
.>=(other : T.class) forall T
Returns whetherother inherits or includes
self, or is equal toself. -
.|(other : U.class) forall U
Returns the union type of
selfandother. - .clone
-
.dup
Returns a shallow copy of this object.
- .hash(hasher)
-
.inspect(io : IO) : Nil
Prints toio an unambiguous and information-rich string representation of this object, typically intended for developers.
-
.name : String
Returns the name of this class.
-
.nilable? : Bool
Returns
trueifnilis an instance of this type. -
.to_s(io : IO) : Nil
Prints a nicely readable and concise string representation of this object, typically intended for users, toio.
Instance Method Summary
-
#<(other : T.class) : Bool forall T
Returns whether this class inherits or includesother.
-
#<=(other : T.class) : Bool forall T
Returns whether this class inherits or includesother, or is equal toother.
-
#==(other : Class) : Bool
Returns whether this class is the same asother.
-
#===(other)
Case equality.
-
#>(other : T.class) : Bool forall T
Returns whetherother inherits or includes
self. -
#>=(other : T.class) forall T
Returns whetherother inherits or includes
self, or is equal toself. -
#|(other : U.class) forall U
Returns the union type of
selfandother. -
#cast(other) : self
Castsother to this class.
- #clone
-
#dup
Returns a shallow copy of this object.
- #hash(hasher)
-
#inspect(io : IO) : Nil
Prints toio an unambiguous and information-rich string representation of this object, typically intended for developers.
-
#name : String
Returns the name of this class.
-
#nilable? : Bool
Returns
trueifnilis an instance of this type. -
#to_s(io : IO) : Nil
Prints a nicely readable and concise string representation of this object, typically intended for users, toio.
Instance methods inherited from struct Value
==(other : Log::Metadata::Value)==(other : JSON::Any)
==(other : YAML::Any)
==(other) ==, dup dup
Instance methods inherited from class Object
! : Bool
!,
!=(other)
!=,
!~(other)
!~,
==(other)
==,
===(other : JSON::Any)===(other : YAML::Any)
===(other) ===, =~(other) =~, as(type : Class) as, as?(type : Class) as?, class class, dup dup, hash(hasher)
hash hash, in?(collection : Object) : Bool
in?(*values : Object) : Bool in?, inspect(io : IO) : Nil
inspect : String inspect, is_a?(type : Class) : Bool is_a?, itself itself, nil? : Bool nil?, not_nil!(message)
not_nil! not_nil!, pretty_inspect(width = 79, newline = "\n", indent = 0) : String pretty_inspect, pretty_print(pp : PrettyPrint) : Nil pretty_print, responds_to?(name : Symbol) : Bool responds_to?, tap(&) tap, to_json(io : IO) : Nil
to_json : String to_json, to_pretty_json(indent : String = " ") : String
to_pretty_json(io : IO, indent : String = " ") : Nil to_pretty_json, to_s(io : IO) : Nil
to_s : String to_s, to_yaml(io : IO) : Nil
to_yaml : String to_yaml, try(&) try, unsafe_as(type : T.class) forall T unsafe_as
Class methods inherited from class Object
from_json(string_or_io : String | IO, root : String)from_json(string_or_io : String | IO) from_json, from_yaml(string_or_io : String | IO) from_yaml
Macros inherited from class Object
class_getter(*names, &block)
class_getter,
class_getter!(*names)
class_getter!,
class_getter?(*names, &block)
class_getter?,
class_property(*names, &block)
class_property,
class_property!(*names)
class_property!,
class_property?(*names, &block)
class_property?,
class_setter(*names)
class_setter,
def_clone
def_clone,
def_equals(*fields)
def_equals,
def_equals_and_hash(*fields)
def_equals_and_hash,
def_hash(*fields)
def_hash,
delegate(*methods, to object)
delegate,
forward_missing_to(delegate)
forward_missing_to,
getter(*names, &block)
getter,
getter!(*names)
getter!,
getter?(*names, &block)
getter?,
property(*names, &block)
property,
property!(*names)
property!,
property?(*names, &block)
property?,
setter(*names)
setter
Constructor Detail
Castsother to this class.
This is the same as usingas, 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
Class Method Detail
Returns whether this class inherits or includesother.
Int32 < Number # => true
Int32 < Value # => true
Int32 < Int32 # => false
Int32 <= String # => false
Returns whether this class inherits or includesother, or is equal toother.
Int32 < Number # => true
Int32 < Value # => true
Int32 <= Int32 # => true
Int32 <= String # => false
Returns whether this class is the same asother.
Int32 == Int32 # => true
Int32 == String # => false
Case equality.
The#=== method is used in acase ... 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
(notablyRegex) can override it to provide meaningful case-equality semantics.
Returns whetherother inherits or includesself.
Number > Int32 # => true
Number > Number # => false
Number > Object # => false
Returns whetherother inherits or includesself, or is equal
toself.
Number >= Int32 # => true
Number >= Number # => true
Number >= Object # => false
Returns the union type ofself andother.
Int32 | Char # => (Int32 | Char)
Returns a shallow copy of this object.
BecauseValue is a value type, this method returnsself,
which already involves a shallow copy of this object because
value types are passed by value.
Prints toio an unambiguous and information-rich string representation of this object, typically intended for developers.
It is similar to#to_s(IO), but often provides more information. Ideally, it should
contain sufficient information to be able to recreate an object with the same value
(given an identical environment).
For types that don't provide a custom implementation of this method,
default implementation delegates to#to_s(IO). This said, it is advisable to
have an appropriate#inspect implementation on every type. Default
implementations are provided byStruct#inspect andReference#inspect.
::p and::p! use this method to print an object inSTDOUT.
Returnstrue ifnil is an instance of this type.
Int32.nilable? # => false
Nil.nilable? # => true
(Int32 | String).nilable? # => false
(Int32 | Nil).nilable? # => true
NoReturn.nilable? # => false
Value.nilable? # => true
Prints a nicely readable and concise string representation of this object, typically intended for users, toio.
This method is called when an object is interpolated in a string literal:
"foo #{bar} baz" # calls bar.to_io with the builder for this string
IO#<< calls this method to append an object to itself:
io << bar # calls bar.to_s(io)
Thus implementations must not interpolateself in a string literal or call
io << self which both would lead to an endless loop.
Also see#inspect(IO).
Instance Method Detail
Returns whether this class inherits or includesother.
Int32 < Number # => true
Int32 < Value # => true
Int32 < Int32 # => false
Int32 <= String # => false
Returns whether this class inherits or includesother, or is equal toother.
Int32 < Number # => true
Int32 < Value # => true
Int32 <= Int32 # => true
Int32 <= String # => false
Returns whether this class is the same asother.
Int32 == Int32 # => true
Int32 == String # => false
Case equality.
The#=== method is used in acase ... 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
(notablyRegex) can override it to provide meaningful case-equality semantics.
Returns whetherother inherits or includesself.
Number > Int32 # => true
Number > Number # => false
Number > Object # => false
Returns whetherother inherits or includesself, or is equal
toself.
Number >= Int32 # => true
Number >= Number # => true
Number >= Object # => false
Returns the union type ofself andother.
Int32 | Char # => (Int32 | Char)
Castsother to this class.
This is the same as usingas, 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
Returns a shallow copy of this object.
BecauseValue is a value type, this method returnsself,
which already involves a shallow copy of this object because
value types are passed by value.
Prints toio an unambiguous and information-rich string representation of this object, typically intended for developers.
It is similar to#to_s(IO), but often provides more information. Ideally, it should
contain sufficient information to be able to recreate an object with the same value
(given an identical environment).
For types that don't provide a custom implementation of this method,
default implementation delegates to#to_s(IO). This said, it is advisable to
have an appropriate#inspect implementation on every type. Default
implementations are provided byStruct#inspect andReference#inspect.
::p and::p! use this method to print an object inSTDOUT.
Returnstrue ifnil is an instance of this type.
Int32.nilable? # => false
Nil.nilable? # => true
(Int32 | String).nilable? # => false
(Int32 | Nil).nilable? # => true
NoReturn.nilable? # => false
Value.nilable? # => true
Prints a nicely readable and concise string representation of this object, typically intended for users, toio.
This method is called when an object is interpolated in a string literal:
"foo #{bar} baz" # calls bar.to_io with the builder for this string
IO#<< calls this method to append an object to itself:
io << bar # calls bar.to_s(io)
Thus implementations must not interpolateself in a string literal or call
io << self which both would lead to an endless loop.
Also see#inspect(IO).