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:
6228 6229 6230 6231 |
# File 'lib/source/ruby.rb', line 6228 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.
6222 6223 6224 6225 6226 |
# File 'lib/source/ruby.rb', line 6222 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:
6233 6234 6235 |
# File 'lib/source/ruby.rb', line 6233 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"
6245 6246 6247 |
# File 'lib/source/ruby.rb', line 6245 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"
6256 6257 6258 |
# File 'lib/source/ruby.rb', line 6256 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
6268 6269 6270 |
# File 'lib/source/ruby.rb', line 6268 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"
6280 6281 6282 |
# File 'lib/source/ruby.rb', line 6280 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.
6290 6291 6292 |
# File 'lib/source/ruby.rb', line 6290 def to_sym return self end |