Package org.jruby.api
Class Define
java.lang.Object
org.jruby.api.Define
Methods which help extension authors define their extension.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic RubyClass
defineClass
(ThreadContext context, String name, RubyClass superClass, ObjectAllocator allocator) Define a new class under the Object namespace.static RubyModule
defineModule
(ThreadContext context) There are times when an anonymous module is needed.static RubyModule
defineModule
(ThreadContext context, String name) Define a new module under the Object namespace.
-
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 useRubyModule.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 contextname
- The name for the new classsuperClass
- The super class for the new classallocator
- An ObjectAllocator instance that can construct instances of the new class.- Returns:
- The new class
-
defineModule
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
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
-