A symbol is a constant that is identified by a name without you having to give it a numeric value.
:hello :welcome :"123" :"symbol with spaces"
Internally a symbol is represented as an Int32
, so it's very efficient.
You can't dynamically create symbols. When you compile your program, each symbol gets assigned a unique number.
Determines if a string needs to be quoted to be used for a symbol.
Returns true
if self
is not equal to other.
Compares symbol with other based on String#<=>
method.
Returns true
if self
is equal to other.
Returns the symbol literal representation as a string.
Returns a unique number for this symbol.
Appends the symbol's name to the passed IO
.
Returns the symbol's name as a String.
Comparable(Symbol)
Value
Object
Object
Determines if a string needs to be quoted to be used for a symbol.
Symbol.needs_quotes? "string" # => false Symbol.needs_quotes? "long string" # => true
Compares symbol with other based on String#<=>
method. Returns -1
, 0
or 1
depending on whether symbol is less than, equal to, or greater than other.
See String#<=>
for more information.
Returns the symbol literal representation as a string.
:crystal.inspect # => ":crystal"
Appends the symbol's name to the passed IO
.
:crystal.to_s # => "crystal"
Returns the symbol's name as a String.
:foo.to_s # => "foo" :"hello world".to_s # => "hello world"
© 2012–2020 Manas Technology Solutions.
Licensed under the Apache License, Version 2.0.
https://crystal-lang.org/api/0.35.1/Symbol.html