abstract class Class

Defined in:

class.cr
primitives.cr

Constructors

Class Method Summary

Instance Method Summary

Instance methods inherited from struct 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
hash(hasher)
hash
, inspect(io : IO) : Nil
inspect : String
inspect
, is_a?(type : Class) : Bool is_a?, itself itself, nil? : Bool nil?, 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)
to_json
to_json
, to_pretty_json(indent : String = " ")
to_pretty_json(io : IO, indent : String = " ")
to_pretty_json
, to_s : String
to_s(io : IO) : Nil
to_s
, to_yaml(io : IO)
to_yaml
to_yaml
, try(&) try, unsafe_as(type : T.class) forall T unsafe_as

Class methods inherited from class Object

from_json(string_or_io, root : String)
from_json(string_or_io)
from_json
, from_yaml(string_or_io : String | IO) from_yaml

Constructor Detail

def self.cast(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

[View source]

Class Method Detail

def self.<(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

[View source]
def self.<=(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

[View source]
def self.==(other : Class) : Bool #

Returns whether this class is the same as other.

Int32 == Int32  # => true
Int32 == String # => false

[View source]
def self.===(other) #
Description copied from class Object

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.


[View source]
def self.>(other : T.class) forall T #

Returns whether other inherits or includes self.

Number > Int32  # => true
Number > Number # => false
Number > Object # => false

[View source]
def self.>=(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

[View source]
def self.clone #

[View source]
def self.dup #
Description copied from struct Value

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.


[View source]
def self.hash(hasher) #

[View source]
def self.inspect(io : IO) : Nil #
Description copied from class Object

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.


[View source]
def self.name : String #

Returns the name of this class.

String.name # => "String"

[View source]
def self.nilable? #

Returns true if this class is Nil.

Int32.nilable? # => false
Nil.nilable?   # => true

[View source]
def self.to_s(io : IO) : Nil #
Description copied from class Object

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.


[View source]
def self.|(other : U.class) forall U #

Returns the union type of self and other.

Int32 | Char # => (Int32 | Char)

[View source]

Instance Method Detail

def <(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

[View source]
def <=(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

[View source]
def ==(other : Class) : Bool #

Returns whether this class is the same as other.

Int32 == Int32  # => true
Int32 == String # => false

[View source]
def ===(other) #
Description copied from class Object

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.


[View source]
def >(other : T.class) forall T #

Returns whether other inherits or includes self.

Number > Int32  # => true
Number > Number # => false
Number > Object # => false

[View source]
def >=(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

[View source]
def cast(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

[View source]
def clone #

[View source]
def dup #
Description copied from struct Value

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.


[View source]
def hash(hasher) #

[View source]
def inspect(io : IO) : Nil #
Description copied from class Object

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.


[View source]
def name : String #

Returns the name of this class.

String.name # => "String"

[View source]
def nilable? #

Returns true if this class is Nil.

Int32.nilable? # => false
Nil.nilable?   # => true

[View source]
def to_s(io : IO) : Nil #
Description copied from class Object

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.


[View source]
def |(other : U.class) forall U #

Returns the union type of self and other.

Int32 | Char # => (Int32 | Char)

[View source]