Programmierung in Ruby

Der Leitfaden der Pragmatischen Programmierer

class Symbol
Parent: Object
Version: 1.6

Index:

id2name inspect to_i to_s


Ein Symbol-Objekt repräsentiert einen Ruby-Namen und wird automatisch unter Verwendung der :name Zeichensyntax generiert. Dasselbe Symbol-Objekt wird für einen gegebenen Namensstring für die Dauer der Programmausführung generiert, egal in welchem Kontext der Name steht oder welche Bedeutung es hat. Also ist z.B. :Fred immer ein und dasselbe Objekt, ob es nun in einem Kontext eine Konstante, in einem zweiten eine Methode und in einem weiteren Kontext eine Klasse ist.

module One
  class Fred
  end
  $f1 = :Fred
end
module Two
  Fred = 1
  $f2 = :Fred
end
def Fred()
end
$f3 = :Fred
$f1.id » 2299150
$f2.id » 2299150
$f3.id » 2299150

instance methods
id2name sym.id2name -> einString

Gibt den zu sym gehörigen Namen zurück.

:fred.id2name » "fred"

inspect sym.inspect -> einString

Gibt die Darstellug von sym als Symbol-Zeichenkette zurück.

:fred.inspect » ":fred"

to_i sym.to_i -> eineFixnum

Gibt eine Ganzzahl zurück, die für jedes Symbol bei der jeweiligen Programmausführung eindeutig ist.

to_s sym.to_s -> einString

Synonym für Symbol#id2name.


Extracted from the book "Programming Ruby - The Pragmatic Programmer's Guide"
Übersetzung: Carsten Schinzer
Für das englische Original:
© 2000 Addison Wesley Longman, Inc. Released under the terms of the Open Publication License V1.0. That reference is available for download.
Diese Lizenz sowie das Original vom Herbst 2001 bilden die Grundlage der Übersetzung
Es wird darauf hingewiesen, dass sich die Lizenz des englischen Originals inzwischen geändert hat.
Für die deutsche Übersetzung:
© 2002 Jürgen Katins
Der Copyright-Eigner stellt folgende Lizenzen zur Verfügung:
Nicht-freie Lizenz:
This material may be distributed only subject to the terms and conditions set forth in the Open Publication License, v1.0 or later (the latest version is presently available at http://www.opencontent.org/openpub/). Distribution of substantively modified versions of this document is prohibited without the explicit permission of the copyright holder. Distribution of the work or derivative of the work in any standard (paper) book form is prohibited unless prior permission is obtained from the copyright holder.
Freie Lizenz:
Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.1 or any later version published by the Free Software Foundation; with no Invariant Sections, with no Front-Cover Texts, and with no Back-Cover Texts. A copy of the license is included in the section entitled "GNU Free Documentation License".