Package org.jruby
Class RubySymbol
java.lang.Object
org.jruby.RubyBasicObject
org.jruby.RubyObject
org.jruby.RubySymbol
- All Implemented Interfaces:
Serializable,Cloneable,Comparable<IRubyObject>,Appendable,Constantizable,InstanceVariables,InternalVariables,IRubyObject,EncodingCapable,MarshalEncoding,CoreObjectType
public class RubySymbol
extends RubyObject
implements MarshalEncoding, EncodingCapable, Constantizable, Appendable
Represents a Ruby symbol (e.g. :bar)
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfacestatic 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
FieldsFields 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, 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 -
Method Summary
Modifier and TypeMethodDescriptionstatic IRubyObjectall_symbols(IRubyObject recv) Deprecated.static IRubyObjectall_symbols(ThreadContext context, IRubyObject recv) voidappendIntoString(RubyString target) 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 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) static StringcheckID(IRubyObject object) Deprecated.intcompareTo(IRubyObject that) Compares this Ruby object with another.constant()static RubyClasscreateSymbolClass(ThreadContext context, RubyClass Object, RubyModule Comparable) downcase(ThreadContext context) downcase(ThreadContext context, IRubyObject arg) downcase(ThreadContext context, IRubyObject arg0, IRubyObject arg1) empty_p(ThreadContext context) encoding(ThreadContext context) end_with_p(ThreadContext context) end_with_p(ThreadContext context, IRubyObject arg) end_with_p(ThreadContext context, IRubyObject[] args) final booleaneql(IRubyObject other) short circuit for Symbol key comparisonbooleanThis override does not do a "checked" dispatch.fstring()final ByteListgetBytes()org.jcodings.EncodingintgetId()Will return the Java interface that most closely can represent this object, when working through Java integration translations.org.jcodings.EncodingThis is overridden in the other concrete Java builtins to provide a fast way to determine what type they are.static RubySymbolgetSymbolLong(Ruby runtime, long id) hash(ThreadContext context) Will return the hash code of this object.inthashCode()This override does not do "checked" dispatch since Object usually has #hash defined.id2name()Deprecated.id2name(ThreadContext context) idString()Return an id string (e.g.static StringidStringFromObject(ThreadContext context, IRubyObject object) static RubySymbolidSymbolFromObject(ThreadContext context, IRubyObject object) inspect(ThreadContext context) Returns a string containing a human-readable representation of obj.booleanIs object immediate (def: Fixnum, Symbol, true, false, nil?).static intjavaStringHashCode(ByteList iso8859) length()Deprecated.length(ThreadContext context) 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) name(ThreadContext context) static RubySymbolnewCalleeSymbolFromCompound(Ruby runtime, String compoundName) static RubySymbolnewConstantSymbol(Ruby runtime, IRubyObject fqn, ByteList bytes) Deprecated.static RubySymbolnewConstantSymbol(ThreadContext context, 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.static RubySymbolnewMethodSymbolFromCompound(Ruby runtime, String compoundName) static 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 IRubyObjectprepareID(ThreadContext context, IRubyObject object) Return the given object if it is a Symbol or String, or convert it to a String.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 to verify the symbol is valid.voidsetEncoding(org.jcodings.Encoding e) booleansingletonClass(ThreadContext context) Will either return the existing singleton class for this object, or create a new one and return that.start_with_p(ThreadContext context) start_with_p(ThreadContext context, IRubyObject arg) start_with_p(ThreadContext context, IRubyObject[] args) succ(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) Deprecated.to_proc(ThreadContext context) to_s(ThreadContext context) to_sym()<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 RubySymboltoSymbol(ThreadContext context, IRubyObject name) static RubySymbolunmarshalFrom(UnmarshalStream input, UnmarshalStream.MarshalState state) Deprecated, for removal: This API element is subject to removal in a future version.upcase(ThreadContext context) upcase(ThreadContext context, IRubyObject arg) upcase(ThreadContext context, IRubyObject arg0, IRubyObject arg1) booleanIs the string this symbol represents a valid attribute setter name.booleanIs the string this symbol represents a valid constant identifier name.booleanIs the string this symbol represents a valid constant identifier name.booleanIs the string this symbol 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, dig, dig1, dig2, eqlInternal, equalInternal, finishObjectClass, inspect, puts, specificEval, toRubyStringMethods inherited from class org.jruby.RubyBasicObject
addFinalizer, addFinalizer, anyToString, callMethod, callMethod, callMethod, callMethod, callMethod, callMethod, callMethod, callMethod, callMethod, callSuper, checkArrayType, checkCallMethod, checkCallMethod, checkFrozen, checkStringType, cloneSetup, convertToArray, convertToFloat, convertToHash, convertToInteger, convertToInteger, convertToInteger, convertToString, copyInstanceVariablesInto, copySpecialInstanceVariables, dataGetStruct, dataGetStructChecked, dataWrapStruct, decode, display, dup, dupFinalizer, dupSetup, ensureInstanceVariablesSettable, eql_p, eql_p, equal_p, evalUnder, extend, fastGetInstanceVariable, fastGetInternalVariable, fastHasInstanceVariable, fastHasInternalVariable, fastSetInstanceVariable, fastSetInternalVariable, finishBasicObjectClass, forEachInstanceVariable, forEachInstanceVariableName, freeze, frozen_p, getCurrentContext, getFFIHandle, getFlag, getInstanceEvalClass, getInstanceEvalClass, getInstanceVariable, getInstanceVariableList, getInstanceVariableNameList, getInstanceVariables, getInternalVariable, getInternalVariables, getMarshalVariableList, getMetaClass, getMetaClass, getNativeHandle, getNativeTypeIndex, getObjectId, getRuntime, getSingletonClass, getSingletonClassClone, getSingletonClassCloneAndAttach, getSingletonClassCloneAndAttach, getType, getVariable, getVariableCount, getVariableList, getVariableNameList, hash, hashyInspect, hasInstanceVariable, hasInstanceVariables, hasInternalVariable, hasVariables, id, infectBy, initialize, initialize_copy, initialize_copy, inspect, inspectHashCode, instance_eval, instance_eval, instance_eval, instance_eval, instance_eval, instance_exec, instance_of_p, instance_variable_defined_p, instance_variable_get, instance_variable_set, instance_variables, isBuiltin, isClass, isFalse, isFrozen, isModule, isNil, isSpecialConst, isSpecialObject, isTaint, isTrue, isUntrusted, kind_of_p, makeMetaClass, makeMetaClass, makeMetaClassBootstrap, method, method, method, method_missing, methods, methods, nil_p, nonFixnumHashCode, nonFixnumHashCode, OBJ_INIT_COPY, objInitCopy, op_not, op_not_equal, op_not_match, private_methods, protected_methods, public_methods, rbClone, rbClone, rbInspect, remove_instance_variable, removeFinalizers, removeInstanceVariable, removeInternalVariable, respond_to_p, respond_to_p, respondsTo, respondsToMissing, respondsToMissing, send, send, send, send, send, setFFIHandle, setFlag, setFrozen, setInstanceVariable, setInternalVariable, setMetaClass, setNativeHandle, setTaint, setUntrusted, setVariable, singleton_method, singleton_method, singleton_method_added, singleton_method_removed, singleton_method_undefined, singleton_methods, specificEval, specificEval, specificEval, specificEval, syncVariables, syncVariables, taint, tainted_p, testFrozen, testFrozen, to_a, to_a, to_s, trust, type, untaint, untrust, untrusted_p, validateInstanceVariable, validateInstanceVariable, validateInstanceVariable, variableTableContains, variableTableFastContains, variableTableFastFetch, variableTableFastStore, variableTableFetch, variableTableRemove, variableTableStore, variableTableSync, yieldUnder, yieldUnderMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.jruby.runtime.builtin.IRubyObject
checkStringType19, dup, marshalLiveVariables
-
Field Details
-
symbolHashSeedK0
Deprecated.- See Also:
-
-
Method Details
-
createSymbolClass
public static RubyClass createSymbolClass(ThreadContext context, RubyClass Object, RubyModule Comparable) -
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- Returns:
- the ClassIndex of the native type this object was constructed from
- 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 to verify 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- Returns:
- Will by default just call the Ruby method "eql?"
-
validConstantName
public boolean validConstantName()Is the string this symbol represents a valid constant identifier name. -
validInstanceVariableName
public boolean validInstanceVariableName()Is the string this symbol represents a valid constant identifier name. -
validClassVariableName
public boolean validClassVariableName()Is the string this symbol represents a valid constant identifier name. -
validAttrsetName
public boolean validAttrsetName()Is the string this symbol represents a valid attribute setter 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:
- boolean
-
singletonClass
Description copied from class:RubyBasicObjectWill either return the existing singleton class for this object, or create a new one and return that. For a few types a singleton class is not possible so it will throw an error.- Specified by:
singletonClassin interfaceIRubyObject- Overrides:
singletonClassin classRubyBasicObject- Parameters:
context- the current thread context- Returns:
- the singleton of this type
-
getSymbolLong
-
newSymbol
Deprecated. -
newHardSymbol
-
newSymbol
-
newSymbol
-
newHardSymbol
-
newHardSymbol
public static RubySymbol newHardSymbol(Ruby runtime, ByteList bytes, RubySymbol.ObjBooleanConsumer<RubySymbol> handler) -
newHardSymbol
-
newMethodSymbolFromCompound
-
newCalleeSymbolFromCompound
-
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
@Deprecated(since="10.0") public static RubySymbol newConstantSymbol(Ruby runtime, IRubyObject fqn, ByteList bytes) Deprecated. -
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:
context- the current thread contextfqn- 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
-
toSymbol
-
constant
- Specified by:
constantin interfaceConstantizable- See Also:
-
inspect
Description copied from class:RubyBasicObjectReturns 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
-
to_s
- Overrides:
to_sin classRubyBasicObject
-
name
-
id2name
Deprecated. -
id2name
-
asString
Description copied from class:RubyBasicObjectrb_obj_as_string First converts this object into a String using the "to_s" method 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:
- string representation
-
fstring
-
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
Description copied from class:RubyBasicObjectWill 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- Parameters:
context- the current thread context- Returns:
- the hash value
-
hashCode
public int hashCode()Description copied from class:RubyObjectThis override does not do "checked" dispatch since Object usually has #hash defined.- Overrides:
hashCodein classRubyObject- Returns:
- the hash code
- See Also:
-
getId
public int getId() -
equals
Description copied from class:RubyObjectThis override does not do a "checked" dispatch.- Overrides:
equalsin classRubyObject- Parameters:
other- object to compare- Returns:
- true if equals
- 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
-
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- Parameters:
context- the thread contextother- arg- Returns:
- true if matches (always nil)
-
match_m
-
match_m
-
match_m
-
match_p
-
match_p
-
op_aref
-
op_aref
-
length
Deprecated.Uselength(ThreadContext)instead.- Returns:
- ""
-
length
-
empty_p
-
start_with_p
-
start_with_p
-
start_with_p
-
end_with_p
-
end_with_p
-
end_with_p
-
upcase
-
upcase
-
upcase
-
downcase
-
downcase
-
downcase
-
swapcase
-
swapcase
-
swapcase
-
capitalize
-
capitalize
-
capitalize
-
encoding
-
to_proc
-
toRefinedProc
-
all_symbols
-
all_symbols
Deprecated. -
unmarshalFrom
@Deprecated(since="10.0", forRemoval=true) public static RubySymbol unmarshalFrom(UnmarshalStream input, UnmarshalStream.MarshalState state) throws IOException Deprecated, for removal: This API element is subject to removal in a future version.- Throws:
IOException
-
toJava
Description copied from interface:IRubyObjectConvert the object to the specified Java class, if possible.- Specified by:
toJavain interfaceIRubyObject- Overrides:
toJavain classRubyBasicObject- Type Parameters:
T- type- Parameters:
target- The target type to which the object should be converted.- Returns:
- java type
- 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
-
getJavaClass
Description copied from class:RubyBasicObjectWill return the Java interface that most closely can represent this object, when working through Java integration translations.- Specified by:
getJavaClassin interfaceIRubyObject- Overrides:
getJavaClassin classRubyBasicObject- Returns:
- the true Java class of this (Ruby) object
-
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
-
checkID
Deprecated. -
idStringFromObject
-
idSymbolFromObject
-
prepareID
Return the given object if it is a Symbol or String, or convert it to a String. MRI: string_for_symbol- Parameters:
context- the current contextobject- the object- Returns:
- the object, if it is a Symbol or String, or a String produced by calling #to_str on the object.
-
appendIntoString
- Specified by:
appendIntoStringin interfaceAppendable
-
taint
Deprecated.- Overrides:
taintin classRubyBasicObject
-
length(ThreadContext)instead.