org.jruby.runtime.ObjectAllocator Java Examples

The following examples show how to use org.jruby.runtime.ObjectAllocator. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RubyOutputStreamWrapper.java    From asciidoctorj with Apache License 2.0 6 votes vote down vote up
public static RubyClass getOrCreateOutputStreamWrapperClass(final Ruby rubyRuntime) {
  RubyModule asciidoctorModule = rubyRuntime.getModule("AsciidoctorJ");
  RubyClass outputStreamWrapperClass = asciidoctorModule.getClass(RUBY_CLASS_NAME);
  if (outputStreamWrapperClass != null) {
    return outputStreamWrapperClass;
  }

  final RubyClass rubyClass = asciidoctorModule.defineClassUnder(RUBY_CLASS_NAME, rubyRuntime.getObject(), new ObjectAllocator() {
    @Override
    public IRubyObject allocate(final Ruby runtime, final RubyClass klazz) {
      return new RubyOutputStreamWrapper(runtime, klazz);
    }
  });

  rubyClass.defineAnnotatedMethods(RubyOutputStreamWrapper.class);

  return rubyClass;
}
 
Example #2
Source File: ExtensionGroupImpl.java    From asciidoctorj with Apache License 2.0 5 votes vote down vote up
static RubyClass createExtensionGroupClass(final Ruby rubyRuntime) {
  final RubyClass extensionGroupClass = rubyRuntime.getModule("AsciidoctorModule")
      .defineClassUnder("ExtensionGroupImpl", rubyRuntime.getObject(), new ObjectAllocator() {
        @Override
        public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
          return new ExtensionGroupRegistrationCallback(runtime, klazz);
        }
      });
  extensionGroupClass.defineAnnotatedMethods(ExtensionGroupRegistrationCallback.class);
  return extensionGroupClass;
}