Class: Symbol
Overview
Symbol
objects represent names and some strings inside the Red interpreter. They are generated using the :name
and :"string"
literals syntax, and by the various to_sym
methods. The same Symbol
object will be created for a given name or string for the duration of an application’s execution, regardless of the context or meaning of that name. Thus if Foo
is a constant in one context, a method in another, and a class in a third, the Symbol
:Foo
will be the same object in all three contexts.
module One
class Foo
end
$f1 = :Foo
end
module Two
Foo = 1
$f2 = :Foo
end
def Foo
end
$f3 = :Foo
$f1.object_id #=> 4190
$f2.object_id #=> 4190
$f3.object_id #=> 4190
Class Method Summary collapse
-
.all_symbols ⇒ Object
call-seq: Symbol.all_symbols -> array.
Instance Method Summary collapse
-
#hash ⇒ Object
:nodoc:.
-
#id2name ⇒ Object
call-seq: sym.id2name -> string sym.to_s -> string.
-
#initialize(value) ⇒ Symbol
constructor
:nodoc:.
-
#inspect ⇒ Object
call-seq: sym.inspect -> string.
-
#to_i ⇒ Object
call-seq: sym.to_i -> fixnum.
-
#to_s ⇒ Object
call-seq: sym.id2name -> string sym.to_s -> string.
-
#to_sym ⇒ Object
call-seq: sym.to_sym -> sym.
Constructor Details
#initialize(value) ⇒ Symbol
:nodoc:
6190 6191 6192 6193 |
# File 'lib/source/ruby.rb', line 6190 def initialize(value) # :nodoc: `this._value=value` `c$Symbol._table[value]=this` end |
Class Method Details
.all_symbols ⇒ Object
call-seq:
Symbol.all_symbols -> array
Returns an array of all the symbols currently in Red’s symbol table.
6184 6185 6186 6187 6188 |
# File 'lib/source/ruby.rb', line 6184 def self.all_symbols `var result=[]` `for(var x in c$Symbol._table){if(c$Symbol._table[x].m$class()==c$Symbol){result.push(c$Symbol._table[x]);}}` return `result` end |
Instance Method Details
#hash ⇒ Object
:nodoc:
6195 6196 6197 |
# File 'lib/source/ruby.rb', line 6195 def hash # :nodoc: `'s_'+this._value` end |
#id2name ⇒ Object
call-seq:
sym.id2name -> string
sym.to_s -> string
Returns the name or string corresponding to sym.
:foo.id2name #=> "foo"
6207 6208 6209 |
# File 'lib/source/ruby.rb', line 6207 def id2name `$q(this._value)` end |
#inspect ⇒ Object
call-seq:
sym.inspect -> string
Returns the representation of sym as a symbol literal.
:foo.inspect #=> ":foo"
6218 6219 6220 |
# File 'lib/source/ruby.rb', line 6218 def inspect `$q(''+this)` end |
#to_i ⇒ Object
call-seq:
sym.to_i -> fixnum
Returns an integer that is unique for each symbol within a particular execution of a program.
:foo.to_i #=> 2019
6230 6231 6232 |
# File 'lib/source/ruby.rb', line 6230 def to_i `this.__id__` end |
#to_s ⇒ Object
call-seq:
sym.id2name -> string
sym.to_s -> string
Returns the name or string corresponding to sym.
:foo.to_s #=> "foo"
6242 6243 6244 |
# File 'lib/source/ruby.rb', line 6242 def to_s `$q(this._value)` end |
#to_sym ⇒ Object
call-seq:
sym.to_sym -> sym
In general, to_sym
returns the Symbol
corresponding to an object. As sym is already a symbol, self
is returned in this case.
6252 6253 6254 |
# File 'lib/source/ruby.rb', line 6252 def to_sym return self end |