Class: Symbol
Overview
Symbol objects represent names and some strings inside the Ruby 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 a program's execution, regardless of the context or meaning of that name. Thus if Fred is a constant in one context, a method in another, and a class in a third, the Symbol :Fred will be the same object in all three contexts.
module One
class Fred
end
$f1 = :Fred
end
module Two
Fred = 1
$f2 = :Fred
end
def Fred()
end
$f3 = :Fred
$f1.object_id #=> 2514190
$f2.object_id #=> 2514190
$f3.object_id #=> 2514190
Class Method Summary (collapse)
-
+ all_symbols
Returns an array of all the symbols currently in Ruby's symbol table.
Instance Method Summary (collapse)
-
- <=>
Compares sym with other in string form.
-
- ==
Equality---If sym and obj are exactly the same symbol, returns true.
-
- =~
Returns sym.to_s =~ obj.
-
- []
Returns sym.to_s[].
-
- capitalize
Same as sym.to_s.capitalize.intern.
-
- casecmp
Case-insensitive version of Symbol#.
-
- description
Returns the name or string corresponding to sym.
-
- downcase
Same as sym.to_s.downcase.intern.
-
- empty?
Returns that sym is :"" or not.
-
- ==
Equality---If sym and obj are exactly the same symbol, returns true.
-
- id2name
Returns the name or string corresponding to sym.
-
- inspect
Returns the representation of sym as a symbol literal.
-
- intern
In general, to_sym returns the Symbol corresponding to an object.
-
- =~
Returns sym.to_s =~ obj.
-
- succ
Same as sym.to_s.succ.intern.
-
- succ
Same as sym.to_s.succ.intern.
-
- swapcase
Same as sym.to_s.swapcase.intern.
-
- to_proc
Returns a Proc object which respond to the given method by sym.
-
- to_s
Returns the name or string corresponding to sym.
-
- to_sym
In general, to_sym returns the Symbol corresponding to an object.
-
- upcase
Same as sym.to_s.upcase.intern.
Methods inherited from NSString
availableStringEncodings, #boolValue, #cStringUsingEncoding:, #canBeConvertedToEncoding:, #capitalizedString, #capitalizedStringWithLocale:, #caseInsensitiveCompare:, #characterAtIndex:, #commonPrefixWithString:options:, #compare:, #compare:options:, #compare:options:range:, #compare:options:range:locale:, #completePathIntoString:caseSensitive:matchesIntoArray:filterTypes:, #componentsSeparatedByCharactersInSet:, #componentsSeparatedByString:, #dataUsingEncoding:, #dataUsingEncoding:allowLossyConversion:, #decomposedStringWithCanonicalMapping, #decomposedStringWithCompatibilityMapping, defaultCStringEncoding, #doubleValue, #encode, #encode!, #enumerateLinesUsingBlock:, #enumerateLinguisticTagsInRange:scheme:options:orthography:usingBlock:, #enumerateSubstringsInRange:options:usingBlock:, #fastestEncoding, #fileSystemRepresentation, #floatValue, #getBytes:maxLength:usedLength:encoding:options:range:remainingRange:, #getCString:maxLength:encoding:, #getCharacters:range:, #getFileSystemRepresentation:maxLength:, #getLineStart:end:contentsEnd:forRange:, localizedNameOfStringEncoding:, localizedStringWithFormat:, pathWithComponents:, string, stringWithCString:encoding:, stringWithCharacters:length:, stringWithContentsOfFile:encoding:error:, stringWithContentsOfFile:usedEncoding:error:, stringWithContentsOfURL:encoding:error:, stringWithContentsOfURL:usedEncoding:error:, stringWithFormat:, stringWithString:, stringWithUTF8String:
Methods inherited from NSObject
#!, #!=, #!~, #===, #Rational, #__callee__, #__method__, #__send__, #__type__, `, alloc, allocWithZone:, #autoContentAccessingProxy, autoload, autoload?, autorelease_pool, #awakeAfterUsingCoder:, binding, block_given?, caller, cancelPreviousPerformRequestsWithTarget:, cancelPreviousPerformRequestsWithTarget:selector:object:, catch, class, classFallbacksForKeyedArchiver, #classForCoder, #classForKeyedArchiver, classForKeyedUnarchiver, #clone, conformsToProtocol:, #copy, copyWithZone:, #dealloc, #define_singleton_method, description, display, #doesNotRecognizeSelector:, #dup, #enum_for, #equal?, #extend, fail, #finalize, format, #forwardInvocation:, #forwardingTargetForSelector:, framework, #freeze, #frozen?, getpass, gets, global_variables, #init, initialize, #initialize_clone, #initialize_copy, #initialize_dup, instanceMethodForSelector:, instanceMethodSignatureForSelector:, #instance_eval, #instance_exec, #instance_of?, #instance_variable_defined?, #instance_variable_get, #instance_variable_set, #instance_variables, instancesRespondToSelector:, isSubclassOfClass:, #is_a?, iterator?, #kind_of?, lambda, load, load_bridge_support_file, load_plist, local_variables, loop, #method, #methodForSelector:, #methodSignatureForSelector:, #methods, #mutableCopy, mutableCopyWithZone:, new, #nil?, open, p, #performSelector:onThread:withObject:waitUntilDone:, #performSelector:onThread:withObject:waitUntilDone:modes:, #performSelector:withObject:afterDelay:, #performSelector:withObject:afterDelay:inModes:, #performSelectorInBackground:withObject:, #performSelectorOnMainThread:withObject:waitUntilDone:, #performSelectorOnMainThread:withObject:waitUntilDone:modes:, print, printf, #private_methods, proc, #protected_methods, #public_method, #public_methods, #public_send, putc, puts, raise, rand, readline, readlines, #replacementObjectForCoder:, #replacementObjectForKeyedArchiver:, require, resolveClassMethod:, resolveInstanceMethod:, #respond_to?, #respond_to_missing?, select, #send, setVersion:, #singleton_methods, sprintf, srand, superclass, #taint, #tainted?, #tap, test, throw, #to_plist, trace_var, trap, #trust, #untaint, untrace_var, #untrust, #untrusted?, version
Constructor Details
This class inherits a constructor from NSObject
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class NSObject
Class Method Details
+ (Array) all_symbols
Returns an array of all the symbols currently in Ruby's symbol table.
Symbol.all_symbols.size #=> 903
Symbol.all_symbols[1,20] #=> [:floor, :ARGV, :Binding, :symlink,
:chown, :EOFError, :$;, :String,
:LOCK_SH, :"setuid?", :$<,
:default_proc, :compact, :extend,
:Tms, :getwd, :$=, :ThreadGroup,
:wait2, :$>]
Instance Method Details
- (-1, ...) <=>(other)
Compares sym with other in string form.
- (Boolean) ==(obj)
Equality---If sym and obj are exactly the same symbol, returns true.
- (Fixnum?) =~(obj)
Returns sym.to_s =~ obj.
- (Symbol) capitalize
Same as sym.to_s.capitalize.intern.
- (-1, ...) casecmp(other)
Case-insensitive version of Symbol#.
- (String) id2name - (String) to_s
Returns the name or string corresponding to sym.
:fred.id2name #=> "fred"
- (Symbol) downcase
Same as sym.to_s.downcase.intern.
- (Boolean) empty?
Returns that sym is :"" or not.
- (Boolean) ==(obj)
Equality---If sym and obj are exactly the same symbol, returns true.
- (String) id2name - (String) to_s
Returns the name or string corresponding to sym.
:fred.id2name #=> "fred"
- (String) inspect
Returns the representation of sym as a symbol literal.
:fred.inspect #=> ":fred"
- (Object) to_sym - (Object) intern
In general, to_sym returns the Symbol corresponding to an object. As sym is already a symbol, self is returned in this case.
- (Fixnum?) =~(obj)
Returns sym.to_s =~ obj.
- (Object) succ
Same as sym.to_s.succ.intern.
- (Object) succ
Same as sym.to_s.succ.intern.
- (Symbol) swapcase
Same as sym.to_s.swapcase.intern.
- (Object) to_proc
Returns a Proc object which respond to the given method by sym.
(1..3).collect(&:to_s) #=> ["1", "2", "3"]
- (String) id2name - (String) to_s
Returns the name or string corresponding to sym.
:fred.id2name #=> "fred"
- (Object) to_sym - (Object) intern
In general, to_sym returns the Symbol corresponding to an object. As sym is already a symbol, self is returned in this case.
- (Symbol) upcase
Same as sym.to_s.upcase.intern.