class Reference
inherits Object
¶
Reference
is the base class of classes you define in your program.
It is set as a class' superclass when you don't specify one:
class MyClass # < Reference
end
A reference type is passed by reference: when you pass it to methods, return it from methods or assign it to variables, a pointer is actually passed.
Invoking new
on a Reference
allocates a new instance on the heap.
The instance's memory is automatically freed (garbage-collected) when
the instance is no longer referred by any other entity in the program.
Direct known subclasses
Array(T)
Benchmark::BM::Job
Benchmark::BM::Tms
Benchmark::IPS::Entry
Benchmark::IPS::Job
Box(T)
Channel(T)
Compress::Gzip::Header
Compress::Zip::File
Compress::Zip::File::Entry
Compress::Zip::Reader
Compress::Zip::Reader::Entry
Compress::Zip::Writer
Compress::Zip::Writer::Entry
Crypto::Bcrypt
Crypto::Bcrypt::Password
Crypto::Blowfish
Crystal::AbstractDefChecker
Crystal::ASTNode
Crystal::CacheDir
Crystal::ClassVarInitializer
Crystal::Codegen::Target
Crystal::CodeGenVisitor::Context
Crystal::CodeGenVisitor::LLVMVar
Crystal::CodeGenVisitor::Phi
Crystal::Command
Crystal::Command::FormatCommand
Crystal::Compiler
Crystal::Compiler::CompilationUnit
Crystal::ContextResult
Crystal::CrystalLibraryPath
Crystal::CrystalLLVMBuilder
Crystal::Doc::Constant
Crystal::Doc::Generator
Crystal::Doc::Macro
Crystal::Doc::Markdown::HTMLRenderer
Crystal::Doc::Markdown::Parser
Crystal::Doc::Method
Crystal::Doc::ProjectInfo
Crystal::Doc::RelativeLocation
Crystal::Doc::Type
Crystal::ExhaustivenessChecker::Target
Crystal::Formatter::CommentInfo
Crystal::HierarchyPrinter
Crystal::ImplementationResult
Crystal::ImplementationTrace
Crystal::Init::Config
Crystal::Init::InitProject
Crystal::Init::View
Crystal::InstanceVarInitializerContainer::InstanceVarInitializer
Crystal::Lexer
Crystal::LiteralExpander
Crystal::LLVMId
Crystal::LLVMTyper
Crystal::Location
Crystal::Macros::ASTNode
Crystal::Match
Crystal::MatchContext
Crystal::NilReason
Crystal::Playground::Agent
Crystal::Playground::EnvironmentHandler
Crystal::Playground::PageHandler
Crystal::Playground::PlaygroundPage
Crystal::Playground::Server
Crystal::Playground::Session
Crystal::Playground::WorkbookHandler
Crystal::PrettyTypeNameJsonConverter
Crystal::ProgressTracker
Crystal::RecursiveStructChecker
Crystal::TablePrint
Crystal::TablePrint::Cell
Crystal::TablePrint::Column
Crystal::Token
Crystal::Transformer
Crystal::Type
Crystal::TypeDeclarationProcessor::InitializeInfo
Crystal::TypeDeclarationProcessor::InstanceVarTypeInfo
Crystal::TypeFilter
Crystal::TypeGuessVisitor::TypeInfo
Crystal::VirtualFile
Crystal::Visitor
CSV
CSV::Builder
CSV::Lexer
CSV::Parser
Deque(T)
Digest
Dir
Exception
Fiber
Hash(K, V)
HTTP::Client
HTTP::Client::Response
HTTP::CompressHandler
HTTP::Cookie
HTTP::Cookies
HTTP::ErrorHandler
HTTP::FormData::Builder
HTTP::FormData::Parser
HTTP::LogHandler
HTTP::Request
HTTP::Server
HTTP::Server::Context
HTTP::Server::RequestProcessor
HTTP::StaticFileHandler
HTTP::WebSocket
HTTP::WebSocketHandler
IO
Iterator::Stop
JSON::Builder
JSON::Lexer
JSON::Parser
JSON::PullParser
JSON::Token
Levenshtein::Finder
LLVM::ABI
LLVM::ABI::FunctionType
LLVM::Builder
LLVM::Context
LLVM::FunctionPassManager
LLVM::GenericValue
LLVM::JITCompiler
LLVM::MemoryBuffer
LLVM::Module
LLVM::ModulePassManager
LLVM::PassManagerBuilder
LLVM::TargetMachine
Log
Log::AsyncDispatcher
Log::Backend
Log::Builder
Log::EntriesChecker
Log::Metadata
Log::SyncDispatcher
MIME::Multipart::Builder
MIME::Multipart::Parser
Mutex
OAuth2::AccessToken
OAuth2::Client
OAuth2::Session
OAuth::AccessToken
OAuth::Consumer
OAuth::RequestToken
OpenSSL::Cipher
OpenSSL::HMAC
OpenSSL::MD5
OpenSSL::SHA1
OpenSSL::SSL::Context
OpenSSL::SSL::Server
OptionParser
PrettyPrint
Process
Process::Status
Random::ISAAC
Random::PCG32
Regex
Spec::Context
Spec::Example
Steppable::StepIterator(T, L, B)
String
StringPool
StringScanner
System::Group
System::User
Time::Location
URI
URI::Params::Builder
URI::Punycode
WeakRef(T)
XML::Attributes
XML::Builder
XML::Namespace
XML::Node
XML::NodeSet
XML::Reader
XML::XPathContext
YAML::Builder
YAML::Nodes::Builder
YAML::Nodes::Node
YAML::ParseContext
YAML::PullParser
Class methods¶
Methods¶
#dup
¶
Returns a shallow copy of this object.
This allocates a new object and copies the contents of
self
into it.
#inspect(io : IO) : Nil
¶
(io : IO) : Nil
Appends a String representation of this object which includes its class name, its object address and the values of all instance variables.
class Person
def initialize(@name : String, @age : Int32)
end
end
Person.new("John", 32).inspect # => #<Person:0x10fd31f20 @name="John", @age=32>
#object_id : UInt64
¶
: UInt64
Returns a UInt64
that uniquely identifies this object.
The returned value is the memory address of this object.
string = "hello"
string.object_id # => 4460249568
pointer = Pointer(String).new(string.object_id)
string2 = pointer.as(String)
string2.object_id == string.object_id # => true
#same?(other : Reference)
¶
(other : Reference)
Returns true
if this reference is the same as other. This is only
true
if this reference's object_id
is the same as other's.
#to_s(io : IO) : Nil
¶
(io : IO) : Nil
Appends a short String representation of this object which includes its class name and its object address.
class Person
def initialize(@name : String, @age : Int32)
end
end
Person.new("John", 32).to_s # => #<Person:0x10a199f20>