/** * Used by the evaluator and the compiler to set a constant by name. This is for a Colon2 const * decl */ public IRubyObject setConstantInModule( String internedName, IRubyObject target, IRubyObject result) { if (!(target instanceof RubyModule)) { throw runtime.newTypeError(target.toString() + " is not a class/module"); } RubyModule module = (RubyModule) target; module.fastSetConstant(internedName, result); return result; }
public static void createReadline(Ruby runtime) throws IOException { ConsoleHolder holder = new ConsoleHolder(); holder.history = new ReadlineHistory(); holder.currentCompletor = null; COMPLETION_CASE_FOLD = runtime.getNil(); RubyModule mReadline = runtime.defineModule("Readline"); mReadline.dataWrapStruct(holder); mReadline.defineAnnotatedMethods(Readline.class); IRubyObject hist = runtime.getObject().callMethod(runtime.getCurrentContext(), "new"); mReadline.fastSetConstant("HISTORY", hist); hist.getSingletonClass().includeModule(runtime.getEnumerable()); hist.getSingletonClass().defineAnnotatedMethods(HistoryMethods.class); // MRI does similar thing on MacOS X with 'EditLine wrapper'. mReadline.fastSetConstant("VERSION", runtime.newString("JLine wrapper")); }
/** * Used by the evaluator and the compiler to set a constant by name This is for a null const decl */ public IRubyObject setConstantInCurrent(String internedName, IRubyObject result) { RubyModule module; if ((module = getCurrentScope().getStaticScope().getModule()) != null) { module.fastSetConstant(internedName, result); return result; } // TODO: wire into new exception handling mechanism throw runtime.newTypeError("no class/module to define constant"); }