Package org.jruby.api

Class Define

java.lang.Object
org.jruby.api.Define

public class Define extends Object
Methods which help extension authors define their extension.
  • Constructor Details

    • Define

      public Define()
  • Method Details

    • defineClass

      public static RubyClass defineClass(ThreadContext context, String name, RubyClass superClass, ObjectAllocator allocator)
      Define a new class under the Object namespace. Roughly equivalent to rb_define_class in MRI. This is a convenience method as you could use RubyModule.defineClassUnder(ThreadContext, String, RubyClass, ObjectAllocator) on a reference to Object but this is such a common thing that it is its own method. Note: If a class already exists for this name it returns it or errors if it is not a Class at all.
      Parameters:
      context - the current thread context
      name - The name for the new class
      superClass - The super class for the new class
      allocator - An ObjectAllocator instance that can construct instances of the new class.
      Returns:
      The new class
    • defineModule

      public static RubyModule defineModule(ThreadContext context, String name)
      Define a new module under the Object namespace. Roughly equivalent to rb_define_module in MRI. Note: If a module already exists for this name it returns it or errors if it is not a Module at all.
      Parameters:
      name - The name of the new module
      Returns:
      The new module or existing one if it has already been defined.
    • defineModule

      public static RubyModule defineModule(ThreadContext context)
      There are times when an anonymous module is needed. It is up to the caller to set it up as a constant or include methods or whatever else is needed.
      Parameters:
      context - the current thread context
      Returns:
      an instance of a RubyModule