Top Description Constructors Methods
org.jruby.api

public Class Define

extends Object
Class Inheritance
Imports
org.jruby.RubyClass, .RubyModule, org.jruby.embed.Extension, org.jruby.runtime.ObjectAllocator, .ThreadContext

Methods which help extension authors define their extension.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public static RubyClass

Returns:

The new class
defineClass
(ThreadContext
the current thread context
context
,
String
The name for the new class
name
,
RubyClass
The super class for the new class
superClass
,
ObjectAllocator
An ObjectAllocator instance that can construct instances of the new class.
allocator
)

Define a new class under the Object namespace.

public static RubyModule

Returns:

The new module or existing one if it has already been defined.
defineModule
(ThreadContext context, String
The name of the new module
name
)

Define a new module under the Object namespace.

public static RubyModule

Returns:

an instance of a RubyModule
defineModule
(ThreadContext
the current thread context
context
)

There are times when an anonymous module is needed.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

Defineback to summary
public Define()

Method Detail

defineClassback to summary
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:ThreadContext

the current thread context

name:String

The name for the new class

superClass:RubyClass

The super class for the new class

allocator:ObjectAllocator

An ObjectAllocator instance that can construct instances of the new class.

Returns:RubyClass

The new class

defineModuleback to summary
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:String

The name of the new module

Returns:RubyModule

The new module or existing one if it has already been defined.

defineModuleback to summary
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:ThreadContext

the current thread context

Returns:RubyModule

an instance of a RubyModule