W3cubDocs

/Crystal

abstract class Class

Defined in:

class.cr
primitives.cr

Constructors

Class Method Summary

Instance Method Summary

Constructor Detail

def self.cast(other) : selfSource

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

Class Method Detail

def self.<(other : T.class) : Bool forall TSource

Returns whether this class inherits or includes other.

Int32 < Number  # => true
Int32 < Value   # => true
Int32 < Int32   # => false
Int32 <= String # => false

def self.<=(other : T.class) : Bool forall TSource

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

def self.==(other : Class) : BoolSource

Returns whether this class is the same as other.

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

def self.===(other)Source

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.

def self.>(other : T.class) forall TSource

Returns whether other inherits or includes self.

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

def self.>=(other : T.class) forall TSource

Returns whether other inherits or includes self, or is equal to self.

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

def self.cloneSource

def self.dupSource

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.

def self.hash(hasher)Source

def self.inspect(io : IO) : NilSource

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.

def self.name : StringSource

Returns the name of this class.

String.name # => "String"

def self.nilable?Source

Returns true if this class is Nil.

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

def self.to_s(io : IO) : NilSource

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.

def self.|(other : U.class) forall USource

Returns the union type of self and other.

Int32 | Char # => (Int32 | Char)

Instance Method Detail

def <(other : T.class) : Bool forall TSource

Returns whether this class inherits or includes other.

Int32 < Number  # => true
Int32 < Value   # => true
Int32 < Int32   # => false
Int32 <= String # => false

def <=(other : T.class) : Bool forall TSource

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

def ==(other : Class) : BoolSource

Returns whether this class is the same as other.

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

def ===(other)Source

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.

def >(other : T.class) forall TSource

Returns whether other inherits or includes self.

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

def >=(other : T.class) forall TSource

Returns whether other inherits or includes self, or is equal to self.

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

def cast(other) : selfSource

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

def cloneSource

def dupSource

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.

def hash(hasher)Source

def inspect(io : IO) : NilSource

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.

def name : StringSource

Returns the name of this class.

String.name # => "String"

def nilable?Source

Returns true if this class is Nil.

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

def to_s(io : IO) : NilSource

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.

def |(other : U.class) forall USource

Returns the union type of self and other.

Int32 | Char # => (Int32 | Char)

© 2012–2020 Manas Technology Solutions.
Licensed under the Apache License, Version 2.0.
https://crystal-lang.org/api/0.35.1/Class.html