Package org.jruby

Class RubyObject

All Implemented Interfaces:
Serializable, Cloneable, Comparable<IRubyObject>, InstanceVariables, InternalVariables, IRubyObject, CoreObjectType
Direct Known Subclasses:
AbstractRubyMethod, Addrinfo, ArrayJavaProxyCreator, ConditionVariable, DynamicLibrary, Enums, Ifaddr, JavaObject, JavaProxy, JavaProxyReflectionObject, JRubyExecutionContextLocal, JRubyObjectInputStream, MemoryObject, Monitor, Mutex, Option, Queue, RubyArgsFile, RubyArithmeticSequence, RubyArray, RubyBinding, RubyBoolean, RubyChain, RubyClassPathVariable, RubyContinuation, RubyConverter, RubyDate, RubyDigest.DigestBase, RubyDigest.DigestClass, RubyDir, RubyEncoding, RubyEnumerator, RubyEnumerator.FeedValue, RubyException, RubyFileStat, RubyGenerator, RubyGzipFile, RubyHash, RubyIO, RubyIOBuffer, RubyMatchData, RubyModule, RubyNameError.RubyNameErrorMessage, RubyNil, RubyNumeric, RubyObject.Data, RubyObjectSpace.AbstractWeakMap, RubyPathname, RubyProc, RubyProcess.RubyStatus, RubyProducer, RubyRandomBase, RubyRange, RubyRegexp, RubyRipper, RubySet, RubyString, RubyStruct, RubySymbol, RubySyslog, RubyThread, RubyThread.Backtrace, RubyThread.Location, RubyThreadGroup, RubyTime, RubyYielder, StructLayout.ArrayProxy, StructLayout.Field, ThreadFiber, TracePoint, Type, VariadicInvoker, ZStream

public class RubyObject extends RubyBasicObject
RubyObject represents the implementation of the Object class in Ruby. As such, it defines very few methods of its own, inheriting most from the included Kernel module. Methods that are implemented here, such as "initialize" should be implemented with care; reification of Ruby classes into Java classes can produce conflicting method names in rare cases. See JRUBY-5906 for an example.
See Also:
  • Field Details

    • OBJECT_ALLOCATOR

      public static final ObjectAllocator OBJECT_ALLOCATOR
      Default allocator instance for all Ruby objects. The only reason to not use this allocator is if you actually need to have all instances of something be a subclass of RubyObject.
      See Also:
    • IVAR_INSPECTING_OBJECT_ALLOCATOR

      public static final ObjectAllocator IVAR_INSPECTING_OBJECT_ALLOCATOR
      Allocator that inspects all methods for instance variables and chooses a concrete class to construct based on that. This allows using specialized subclasses to hold instance variables in fields rather than always holding them in an array.
    • REIFYING_OBJECT_ALLOCATOR

      public static final ObjectAllocator REIFYING_OBJECT_ALLOCATOR
  • Constructor Details

    • RubyObject

      public RubyObject(Ruby runtime, RubyClass metaClass)
      Standard path for object creation. Objects are entered into ObjectSpace only if ObjectSpace is enabled.
      Parameters:
      runtime - the runtime
      metaClass - the metaclass
    • RubyObject

      public RubyObject(RubyClass metaClass)
      Path for objects that don't enter objectspace.
      Parameters:
      metaClass - the metaclass
    • RubyObject

      @Deprecated protected RubyObject(Ruby runtime, RubyClass metaClass, boolean useObjectSpace, boolean canBeTainted)
      Deprecated.
    • RubyObject

      protected RubyObject(Ruby runtime, RubyClass metaClass, boolean useObjectSpace)
      Path for objects who want to decide whether they don't want to be in ObjectSpace even when it is on. (notably used by objects being considered immediate, they'll always pass false here)
      Parameters:
      runtime - the runtime
      metaClass - the metaclass
      useObjectSpace - to enable object space
  • Method Details

    • finishObjectClass

      public static void finishObjectClass(RubyClass Object)
      Will create the Ruby class Object in the runtime specified. This method needs to take the actual class as an argument because of the Object class' central part in runtime initialization.
      Parameters:
      Object - the object claass
    • attachToObjectSpace

      public void attachToObjectSpace()
      Will make sure that this object is added to the current object space.
      See Also:
    • getNativeClassIndex

      public ClassIndex getNativeClassIndex()
      This 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:
      getNativeClassIndex in interface CoreObjectType
      Overrides:
      getNativeClassIndex in class RubyBasicObject
      Returns:
      the ClassIndex of the native type this object was constructed from
      See Also:
    • puts

      @Deprecated public static void puts(Object obj)
      Deprecated.
      no longer used - uses Java's System.out
      Simple helper to print any objects.
      Parameters:
      obj - to puts
    • equals

      public boolean equals(Object other)
      This override does not do a "checked" dispatch.
      Overrides:
      equals in class RubyBasicObject
      Parameters:
      other - object to compare
      Returns:
      true if equals
      See Also:
    • toRubyString

      public RubyString toRubyString(ThreadContext context)
      The default toString method is just a wrapper that calls the Ruby "to_s" method. This will raise if it is not actually a Ruby String.
      Parameters:
      context - thread context this is executing on.
      Returns:
      the string.
    • toString

      public String toString()
      The default toString method is just a wrapper that calls the Ruby "to_s" method.
      Overrides:
      toString in class Object
      Returns:
      string representation
    • callInit

      public final void callInit(IRubyObject[] args, Block block)
      Call the Ruby initialize method with the supplied arguments and block.
      Parameters:
      args - args
      block - block
    • callInit

      public final void callInit(Block block)
      Call the Ruby initialize method with the supplied arguments and block.
      Parameters:
      block - block
    • callInit

      public final void callInit(IRubyObject arg0, Block block)
      Call the Ruby initialize method with the supplied arguments and block.
      Parameters:
      arg0 - arg0
      block - block
    • callInit

      public final void callInit(IRubyObject arg0, IRubyObject arg1, Block block)
      Call the Ruby initialize method with the supplied arguments and block.
      Parameters:
      arg0 - arg0
      arg1 - arg1
      block - block
    • callInit

      public final void callInit(IRubyObject arg0, IRubyObject arg1, IRubyObject arg2, Block block)
    • callInit

      public final void callInit(ThreadContext context, IRubyObject[] args, Block block)
    • callInit

      public final void callInit(ThreadContext context, Block block)
    • callInit

      public final void callInit(ThreadContext context, IRubyObject arg0, Block block)
    • callInit

      public final void callInit(ThreadContext context, IRubyObject arg0, IRubyObject arg1, Block block)
    • callInit

      public final void callInit(ThreadContext context, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2, Block block)
    • convertToType

      @Deprecated public final IRubyObject convertToType(RubyClass target, int convertMethodIndex)
      Deprecated.
    • specificEval

      @Deprecated public IRubyObject specificEval(ThreadContext context, RubyModule mod, IRubyObject[] args, Block block, EvalType evalType)
      Deprecated.
    • op_eqq

      public IRubyObject op_eqq(ThreadContext context, IRubyObject other)
      rb_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_eqq in interface IRubyObject
      Overrides:
      op_eqq in class RubyBasicObject
    • equalInternal

      public static boolean equalInternal(ThreadContext context, IRubyObject a, IRubyObject b)
      Helper method for checking equality, first using Java identity equality, and then calling the "==" method.
      Parameters:
      context - the thread context
      a - first comparator
      b - second comparator
      Returns:
      true if equal
    • eqlInternal

      protected static boolean eqlInternal(ThreadContext context, IRubyObject a, IRubyObject b)
      Helper method for checking equality, first using Java identity equality, and then calling the "eql?" method.
      Parameters:
      context - the thread context
      a - first comparator
      b - second comparator
      Returns:
      true if eql
    • hashCode

      public int hashCode()
      This override does not do "checked" dispatch since Object usually has #hash defined.
      Overrides:
      hashCode in class RubyBasicObject
      Returns:
      the hash code
      See Also:
    • inspect

      public static RubyString inspect(ThreadContext context, IRubyObject object)
      rb_inspect The internal helper that ensures a RubyString instance is returned so dangerous casting can be omitted Preferred over callMethod(context, "inspect")
      Parameters:
      context - the thread context
      object - the object to inspect
      Returns:
      the string
    • dig

      public static IRubyObject dig(ThreadContext context, IRubyObject obj, IRubyObject[] args, int idx)
    • dig1

      public static IRubyObject dig1(ThreadContext context, IRubyObject obj, IRubyObject arg1)
    • dig2

      public static IRubyObject dig2(ThreadContext context, IRubyObject obj, IRubyObject arg1, IRubyObject arg2)