Package org.jruby
Class RubySymbol
java.lang.Object
org.jruby.RubyBasicObject
org.jruby.RubyObject
org.jruby.RubySymbol
- All Implemented Interfaces:
Serializable,Cloneable,Comparable<IRubyObject>,Constantizable,InstanceVariables,InternalVariables,IRubyObject,EncodingCapable,MarshalEncoding,CoreObjectType
public class RubySymbol
extends RubyObject
implements MarshalEncoding, EncodingCapable, Constantizable
Represents a Ruby symbol (e.g. :bar)
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceprivate static final classstatic final classNested classes/interfaces inherited from class org.jruby.RubyObject
RubyObject.DataNested classes/interfaces inherited from class org.jruby.RubyBasicObject
RubyBasicObject.Finalizer -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate Objectprivate Stringprivate final intprivate final intprivate final Stringprivate final ByteListstatic final longDeprecated.private SymbolNameTypeFields inherited from class org.jruby.RubyObject
IVAR_INSPECTING_OBJECT_ALLOCATOR, OBJECT_ALLOCATOR, REIFYING_OBJECT_ALLOCATORFields inherited from class org.jruby.RubyBasicObject
ALL_F, BASICOBJECT_ALLOCATOR, COMPARE_BY_IDENTITY_F, ERR_INSECURE_SET_INST_VAR, FALSE_F, FL_USHIFT, flags, FROZEN_F, IS_OVERLAID_F, metaClass, NEVER, NIL_F, REFINED_MODULE_F, STAMP_OFFSET, TAINTED_F, UNDEF, UNTRUST_F, USER0_F, USER1_F, USER2_F, USER3_F, USER4_F, USER5_F, USER6_F, USER7_F, USER8_F, USER9_F, USERA_F, VAR_TABLE_OFFSET, varTable, varTableStampFields inherited from interface org.jruby.runtime.builtin.IRubyObject
NULL_ARRAY -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateRubySymbol(Ruby runtime, String internedSymbol) privateRubySymbol(Ruby runtime, String internedSymbol, ByteList symbolBytes) -
Method Summary
Modifier and TypeMethodDescriptionstatic IRubyObjectall_symbols(IRubyObject recv) Deprecated.static IRubyObjectall_symbols(ThreadContext context, IRubyObject recv) final Stringrb_to_idvoidassociateEncoding(org.jcodings.Encoding encoding) RubySymbol is created by passing in a String and bytes are extracted from that.asString()rb_obj_as_string First converts this object into a String using the "to_s" method, infects it with the current taint and returns it.asWriter()Make an instance variable out of this symbol (e.g.capitalize(ThreadContext context) capitalize(ThreadContext context, IRubyObject arg) capitalize(ThreadContext context, IRubyObject arg0, IRubyObject arg1) casecmp(ThreadContext context, IRubyObject other) casecmp_p(ThreadContext context, IRubyObject other) intcompareTo(IRubyObject that) Compares this Ruby object with another.constant()static RubyClasscreateSymbolClass(Ruby runtime) downcase(ThreadContext context) downcase(ThreadContext context, IRubyObject arg) downcase(ThreadContext context, IRubyObject arg0, IRubyObject arg1) empty_p(ThreadContext context) encoding(ThreadContext context) final booleaneql(IRubyObject other) short circuit for Symbol key comparisonbooleanThis override does not do a "checked" dispatch.final ByteListgetBytes()org.jcodings.EncodingintgetId()org.jcodings.EncodingThis is overridden in the other concrete Java builtins to provide a fast way to determine what type they are.rb_singleton_class Note: this method is specialized for RubyFixnum, RubySymbol, RubyNil and RubyBoolean Will either return the existing singleton class for this object, or create a new one and return that.static RubySymbolgetSymbolLong(Ruby runtime, long id) hash()Deprecated.hash(ThreadContext context) inthashCode()This override does not do "checked" dispatch since Object usually has #hash defined.id2name()id2name(ThreadContext context) idString()Return an id string (e.g.inspect()rb_obj_inspect call-seq: obj.inspect => string Returns a string containing a human-readable representation of obj.(package private) final RubyStringinspect(ThreadContext context) inspect19(ThreadContext context) Deprecated.private static booleanisIdentChar(char c) private static booleanprivate static booleanisIdentStart(char c) booleanIs object immediate (def: Fixnum, Symbol, true, false, nil?).private booleanisPrintable(Ruby runtime) private static booleanis_special_global_name from parse.c.private static booleanisSymbolLocal(String str, char first, int length) private static booleanisSymbolName(String str) private static booleanisSymbolNameCommon(String str, char first, int length) private static intjavaStringHashCode(String str) static intjavaStringHashCode(ByteList iso8859) length()match_m(ThreadContext context, IRubyObject[] args, Block block) match_m(ThreadContext context, IRubyObject other, Block block) match_m(ThreadContext context, IRubyObject other, IRubyObject pos, Block block) match_p(ThreadContext context, IRubyObject other) match_p(ThreadContext context, IRubyObject other, IRubyObject pos) static RubySymbolnewConstantSymbol(Ruby runtime, IRubyObject fqn, ByteList bytes) Create a symbol whose intention is to be used as a constant.static RubySymbolnewHardSymbol(Ruby runtime, String name) static RubySymbolnewHardSymbol(Ruby runtime, String name, org.jcodings.Encoding encoding) static RubySymbolnewHardSymbol(Ruby runtime, IRubyObject name) static RubySymbolnewHardSymbol(Ruby runtime, ByteList bytes) static RubySymbolnewHardSymbol(Ruby runtime, ByteList bytes, RubySymbol.ObjBooleanConsumer<RubySymbol> handler) static RubySymbolnewIDSymbol(Ruby runtime, ByteList bytes) Generic identifier symbol creation (or retrieval) method.static RubySymbolnewIDSymbol(Ruby runtime, ByteList bytes, RubySymbol.ObjBooleanConsumer<RubySymbol> handler) Generic identifier symbol creation (or retrieval) method that invokes a handler before storing new symbols.private RubyStringstatic RubySymbolstatic RubySymbolstatic RubySymbolnewSymbol(Ruby runtime, IRubyObject name) Deprecated.static RubySymbolstatic RubySymbolnewSymbol(Ruby runtime, ByteList bytes, RubySymbol.ObjBooleanConsumer<RubySymbol> handler) Return the symbol in the symbol table if it exists, null otherwise.static StringobjectToSymbolString(IRubyObject object) Properly stringify an object for the current "raw bytes" representation of a symbol.op_aref(ThreadContext context, IRubyObject arg) op_aref(ThreadContext context, IRubyObject arg1, IRubyObject arg2) op_cmp(ThreadContext context, IRubyObject other) op_eqq(ThreadContext context, IRubyObject other) rb_equal The Ruby "===" method is used by default in case/when statements.op_equal(ThreadContext context, IRubyObject other) rb_obj_equal Will by default use identity equality to compare objects.op_match(ThreadContext context, IRubyObject other) rb_obj_pattern_match call-seq: obj =~ other => nil Pattern Match---Overridden by descendents (notablyRegexpandString) to provide meaningful pattern-match semantics.static RubySymbolretrieveIDSymbol(IRubyObject name) When we know we need an entry in the symbol table because the provided name will be needed to be accessed as a valid identifier later we can call this.static RubySymbolretrieveIDSymbol(IRubyObject name, RubySymbol.ObjBooleanConsumer<RubySymbol> handler) Retrieve an ID symbol but call the handler before any new symbol is added to the symbol table.voidsetEncoding(org.jcodings.Encoding e) booleansucc(ThreadContext context) swapcase(ThreadContext context) swapcase(ThreadContext context, IRubyObject arg) swapcase(ThreadContext context, IRubyObject arg0, IRubyObject arg1) static ByteListsymbolBytesFromString(Ruby runtime, String internedSymbol) taint(ThreadContext context) rb_obj_taint call-seq: obj.taint -> obj Marks obj as tainted---if the$SAFElevel is set appropriately, many method calls which might alter the running programs environment will refuse to accept tainted strings.to_proc(ThreadContext context) to_s()rb_any_to_s call-seq: obj.to_s => string Returns a string representing obj.(package private) final RubyStringto_s(ThreadContext context) to_sym()to_sym19()Deprecated.<T> TConvert the object to the specified Java class, if possible.toRefinedProc(ThreadContext context, StaticScope scope) final StringtoString()Print a string for internal debugging purposes.static RubySymbolunmarshalFrom(UnmarshalStream input, UnmarshalStream.MarshalState state) upcase(ThreadContext context) upcase(ThreadContext context, IRubyObject arg) upcase(ThreadContext context, IRubyObject arg0, IRubyObject arg1) booleanIs the string this constant represents a valid constant identifier name.booleanIs the string this constant represents a valid constant identifier name.booleanIs the string this constant represents a valid constant identifier name.booleanMethods inherited from class org.jruby.RubyObject
attachToObjectSpace, callInit, callInit, callInit, callInit, callInit, callInit, callInit, callInit, callInit, callInit, convertToType, createObjectClass, dig, dig1, dig2, eqlInternal, equalInternal, inspect, puts, specificEval, toRubyStringMethods inherited from class org.jruby.RubyBasicObject
addFinalizer, anyToString, callMethod, callMethod, callMethod, callMethod, callMethod, callMethod, callMethod, callMethod, callMethod, callSuper, checkArrayType, checkCallMethod, checkCallMethod, checkFrozen, checkStringType, checkStringType19, convertToArray, convertToFloat, convertToHash, convertToInteger, convertToInteger, convertToInteger, convertToString, copyInstanceVariablesInto, copySpecialInstanceVariables, createBasicObjectClass, dataGetStruct, dataGetStructChecked, dataWrapStruct, decode, defaultToJava, display, dup, ensureInstanceVariablesSettable, eql_p, equal_p, equal_p19, evalUnder, extend, fastGetInstanceVariable, fastGetInternalVariable, fastHasInstanceVariable, fastHasInternalVariable, fastSetInstanceVariable, fastSetInternalVariable, freeze, frozen_p, getFFIHandle, getFlag, getInstanceEvalClass, getInstanceVariable, getInstanceVariableList, getInstanceVariableNameList, getInstanceVariables, getInternalVariable, getInternalVariables, getJavaClass, getMetaClass, getMetaClass, getNativeHandle, getNativeTypeIndex, getObjectId, getRuntime, getSingletonClassClone, getSingletonClassCloneAndAttach, getType, getVariable, getVariableCount, getVariableList, getVariableNameList, hashyInspect, hasInstanceVariable, hasInstanceVariables, hasInternalVariable, hasVariables, id, infectBy, infectBy, infectBy, initialize, initialize_copy, initialize19, inspectHashCode, instance_eval, instance_eval, instance_eval, instance_eval, instance_eval19, instance_eval19, instance_eval19, instance_eval19, instance_exec, instance_exec19, instance_of_p, instance_variable_defined_p, instance_variable_get, instance_variable_set, instance_variables, instance_variables19, isBuiltin, isClass, isFalse, isFrozen, isModule, isNil, isSpecialConst, isSpecialObject, isTaint, isTrue, isUntrusted, kind_of_p, makeMetaClass, method, method_missing, method_missing19, method19, methods, methods, methods19, methodsImpl, nil_p, nonFixnumHashCode, OBJ_INIT_COPY, objInitCopy, op_equal_19, op_match19, op_not, op_not_equal, op_not_match, private_methods, private_methods19, protected_methods, protected_methods19, public_methods, public_methods19, rbClone, rbClone, rbInspect, recacheBuiltinMethods, remove_instance_variable, removeFinalizers, removeInstanceVariable, removeInternalVariable, respond_to_p, respond_to_p, respond_to_p, respond_to_p19, respond_to_p19, respondsTo, respondsToMissing, respondsToMissing, send, send, send, send, send, send19, send19, send19, send19, setFFIHandle, setFlag, setFrozen, setInstanceVariable, setInternalVariable, setMetaClass, setNativeHandle, setTaint, setUntrusted, setVariable, singleton_method, singleton_method_added, singleton_method_added19, singleton_method_removed, singleton_method_removed19, singleton_method_undefined, singleton_method_undefined19, singleton_methods, specificEval, specificEval, specificEval, specificEval, syncVariables, syncVariables, taint, tainted, tainted_p, testFrozen, testFrozen, to_a, to_a, trust, type, type_deprecated, untaint, untrust, untrusted_p, validateInstanceVariable, validateInstanceVariable, validateInstanceVariable, variableTableContains, variableTableFastContains, variableTableFastFetch, variableTableFastStore, variableTableFetch, variableTableRemove, variableTableStore, variableTableSync, yieldUnder, yieldUnder
-
Field Details
-
symbolHashSeedK0
Deprecated.- See Also:
-
symbol
-
id
private final int id -
symbolBytes
-
hashCode
private final int hashCode -
decodedString
-
constant
-
type
-
-
Constructor Details
-
RubySymbol
- Parameters:
runtime-internedSymbol- the String value of the new Symbol. This must have been previously internedsymbolBytes- the ByteList of the symbol's string representation
-
RubySymbol
-
-
Method Details
-
createSymbolClass
-
getNativeClassIndex
Description copied from class:RubyObjectThis is overridden in the other concrete Java builtins to provide a fast way to determine what type they are. Will generally return a value from org.jruby.runtime.ClassIndex- Specified by:
getNativeClassIndexin interfaceCoreObjectType- Overrides:
getNativeClassIndexin classRubyObject- See Also:
-
asJavaString
rb_to_id- Specified by:
asJavaStringin interfaceIRubyObject- Overrides:
asJavaStringin classRubyBasicObject- Returns:
- a String representation of the symbol
-
idString
Return an id string (e.g. raw ISO-8859_1 charset String) for use with our method tables etc. -
toString
Print a string for internal debugging purposes. This does a half-hearted attempt at representing the string in a displayable fashion for for error messages you should use RubyStringBuilder.str + ids + types to build up the error message. For identifier strings you should use idString(). For non-identifier strings where you want a raw String you should use asJavaString().- Overrides:
toStringin classRubyObject- Returns:
- a String
-
getBytes
-
asWriter
Make an instance variable out of this symbol (e.g. :foo will generate :foo=).- Returns:
- the new symbol
-
asInstanceVariable
-
retrieveIDSymbol
When we know we need an entry in the symbol table because the provided name will be needed to be accessed as a valid identifier later we can call this. If there is not already an entry we will return a new symbol. Otherwise, the existing entry.- Parameters:
name- to get symbol table entry for (it may be a symbol already)- Returns:
- the symbol table entry.
-
retrieveIDSymbol
public static RubySymbol retrieveIDSymbol(IRubyObject name, RubySymbol.ObjBooleanConsumer<RubySymbol> handler) Retrieve an ID symbol but call the handler before any new symbol is added to the symbol table. This can be used for verifying the symbol is valid.- Parameters:
name- to get symbol table entry for (it may be a symbol already)- Returns:
- the symbol table entry.
-
associateEncoding
public void associateEncoding(org.jcodings.Encoding encoding) RubySymbol is created by passing in a String and bytes are extracted from that. We will pass in encoding of that string after construction but before use so it does not forget what it is. -
eql
short circuit for Symbol key comparison- Specified by:
eqlin interfaceIRubyObject- Overrides:
eqlin classRubyBasicObject
-
validConstantName
public boolean validConstantName()Is the string this constant represents a valid constant identifier name. -
validInstanceVariableName
public boolean validInstanceVariableName()Is the string this constant represents a valid constant identifier name. -
validClassVariableName
public boolean validClassVariableName()Is the string this constant represents a valid constant identifier name. -
validLocalVariableName
public boolean validLocalVariableName() -
isImmediate
public boolean isImmediate()Description copied from class:RubyBasicObjectIs object immediate (def: Fixnum, Symbol, true, false, nil?).- Specified by:
isImmediatein interfaceIRubyObject- Overrides:
isImmediatein classRubyBasicObject- Returns:
-
getSingletonClass
Description copied from class:RubyBasicObjectrb_singleton_class Note: this method is specialized for RubyFixnum, RubySymbol, RubyNil and RubyBoolean Will either return the existing singleton class for this object, or create a new one and return that.- Specified by:
getSingletonClassin interfaceIRubyObject- Overrides:
getSingletonClassin classRubyBasicObject- Returns:
- the Ruby singleton class
-
getSymbolLong
-
newSymbol
Deprecated. -
newHardSymbol
-
newSymbol
-
newSymbol
-
newHardSymbol
-
newHardSymbol
public static RubySymbol newHardSymbol(Ruby runtime, ByteList bytes, RubySymbol.ObjBooleanConsumer<RubySymbol> handler) -
newHardSymbol
-
newSymbol
public static RubySymbol newSymbol(Ruby runtime, ByteList bytes, RubySymbol.ObjBooleanConsumer<RubySymbol> handler) Return the symbol in the symbol table if it exists, null otherwise. This method will not create the symbol if it does not exist.- Parameters:
runtime-bytes-- Returns:
-
newIDSymbol
Generic identifier symbol creation (or retrieval) method.- Parameters:
runtime- of this Ruby instance.bytes- to be made into a symbol (or to help retreive existing symbol)- Returns:
- a new or existing symbol
-
newIDSymbol
public static RubySymbol newIDSymbol(Ruby runtime, ByteList bytes, RubySymbol.ObjBooleanConsumer<RubySymbol> handler) Generic identifier symbol creation (or retrieval) method that invokes a handler before storing new symbols.- Parameters:
runtime- of this Ruby instance.bytes- to be made into a symbol (or to help retreive existing symbol)- Returns:
- a new or existing symbol
-
newConstantSymbol
Create a symbol whose intention is to be used as a constant. This will not only guarantee a symbol entry in the table but it will also verify the symbol conforms as a valid constant identifier.- Parameters:
runtime- of this Ruby instance.fqn- if this constant symbol is part of a broader chain this is used for full name error reporting.bytes- to be made into a symbol (or to help retreive existing symbol)- Returns:
- a new or existing symbol
-
newSymbol
-
newHardSymbol
-
constant
- Specified by:
constantin interfaceConstantizable- See Also:
-
inspect
Description copied from class:RubyBasicObjectrb_obj_inspect call-seq: obj.inspect => string Returns a string containing a human-readable representation of obj. If not overridden, uses theto_smethod to generate the string. [ 1, 2, 3..4, 'five' ].inspect #=> "[1, 2, 3..4, \"five\"]" Time.new.inspect #=> "Wed Apr 09 08:54:39 CDT 2003"- Specified by:
inspectin interfaceIRubyObject- Overrides:
inspectin classRubyBasicObject- Returns:
- String
-
inspect
-
inspect
-
inspect19
Deprecated. -
to_s
Description copied from class:RubyBasicObjectrb_any_to_s call-seq: obj.to_s => string Returns a string representing obj. The defaultto_sprints the object's class and an encoding of the object id. As a special case, the top-level object that is the initial execution context of Ruby programs returns ``main.''- Overrides:
to_sin classRubyBasicObject
-
to_s
-
to_s
-
id2name
-
id2name
-
asString
Description copied from class:RubyBasicObjectrb_obj_as_string First converts this object into a String using the "to_s" method, infects it with the current taint and returns it. If to_s doesn't return a Ruby String,RubyBasicObject.anyToString()is used instead.- Specified by:
asStringin interfaceIRubyObject- Overrides:
asStringin classRubyBasicObject- Returns:
-
op_eqq
Description copied from class:RubyObjectrb_equal The Ruby "===" method is used by default in case/when statements. The Object implementation first checks Java identity equality and then calls the "==" method too.- Specified by:
op_eqqin interfaceIRubyObject- Overrides:
op_eqqin classRubyObject
-
op_equal
Description copied from class:RubyBasicObjectrb_obj_equal Will by default use identity equality to compare objects. This follows the Ruby semantics. The name of this method doesn't follow the convention because hierarchy problems- Specified by:
op_equalin interfaceIRubyObject- Overrides:
op_equalin classRubyBasicObject
-
hash
Deprecated.Description copied from class:RubyBasicObjectrb_obj_id Will return the hash code of this object. In comparison to MRI, this method will use the Java identity hash code instead of using rb_obj_id, since the usage of id in JRuby will incur the cost of some. ObjectSpace maintenance.- Overrides:
hashin classRubyBasicObject
-
hash
-
hashCode
public int hashCode()Description copied from class:RubyObjectThis override does not do "checked" dispatch since Object usually has #hash defined.- Overrides:
hashCodein classRubyObject- See Also:
-
getId
public int getId() -
equals
Description copied from class:RubyObjectThis override does not do a "checked" dispatch.- Overrides:
equalsin classRubyObject- See Also:
-
compareTo
Description copied from class:RubyBasicObjectCompares this Ruby object with another.- Specified by:
compareToin interfaceComparable<IRubyObject>- Overrides:
compareToin classRubyBasicObject- Parameters:
that- another IRubyObject- Returns:
- 0 if equal, < 0 if this is less than other, > 0 if this is greater than other
- See Also:
-
to_sym
-
to_sym19
Deprecated. -
taint
Description copied from class:RubyBasicObjectrb_obj_taint call-seq: obj.taint -> obj Marks obj as tainted---if the$SAFElevel is set appropriately, many method calls which might alter the running programs environment will refuse to accept tainted strings.- Overrides:
taintin classRubyBasicObject
-
succ
-
op_cmp
- Overrides:
op_cmpin classRubyBasicObject
-
casecmp
-
casecmp_p
-
op_match
Description copied from class:RubyBasicObjectrb_obj_pattern_match call-seq: obj =~ other => nil Pattern Match---Overridden by descendents (notablyRegexpandString) to provide meaningful pattern-match semantics.- Overrides:
op_matchin classRubyBasicObject
-
match_m
-
match_m
-
match_m
-
match_p
-
match_p
-
op_aref
-
op_aref
-
length
-
empty_p
-
upcase
-
upcase
-
upcase
-
downcase
-
downcase
-
downcase
-
swapcase
-
swapcase
-
swapcase
-
capitalize
-
capitalize
-
capitalize
-
encoding
-
to_proc
-
toRefinedProc
-
isIdentStart
private static boolean isIdentStart(char c) -
isIdentChar
private static boolean isIdentChar(char c) -
isIdentifier
-
isSpecialGlobalName
is_special_global_name from parse.c.- Parameters:
s-- Returns:
-
isPrintable
-
isSymbolName
-
isSymbolNameCommon
-
isSymbolLocal
-
all_symbols
-
all_symbols
Deprecated. -
unmarshalFrom
public static RubySymbol unmarshalFrom(UnmarshalStream input, UnmarshalStream.MarshalState state) throws IOException - Throws:
IOException
-
toJava
Description copied from interface:IRubyObjectConvert the object to the specified Java class, if possible.- Specified by:
toJavain interfaceIRubyObject- Overrides:
toJavain classRubyBasicObject- Parameters:
target- The target type to which the object should be converted.- See Also:
-
symbolBytesFromString
-
getEncoding
public org.jcodings.Encoding getEncoding()- Specified by:
getEncodingin interfaceEncodingCapable
-
setEncoding
public void setEncoding(org.jcodings.Encoding e) - Specified by:
setEncodingin interfaceEncodingCapable
-
javaStringHashCode
-
javaStringHashCode
-
shouldMarshalEncoding
public boolean shouldMarshalEncoding()- Specified by:
shouldMarshalEncodingin interfaceMarshalEncoding
-
getMarshalEncoding
public org.jcodings.Encoding getMarshalEncoding()- Specified by:
getMarshalEncodingin interfaceMarshalEncoding
-
objectToSymbolString
Properly stringify an object for the current "raw bytes" representation of a symbol. Symbols are represented internally as a Java string, but decoded using raw bytes in ISO-8859-1 representation. This means they do not in their normal String form represent a readable Java string, but it does allow differently-encoded strings to map to different symbol objects. See #736- Parameters:
object- the object to symbolify- Returns:
- the symbol string associated with the object's string representation
-