コード例 #1
0
ファイル: RubyThread.java プロジェクト: nahi/jruby
  public static RubyClass createThreadClass(Ruby runtime) {
    // FIXME: In order for Thread to play well with the standard 'new' behavior,
    // it must provide an allocator that can create empty object instances which
    // initialize then fills with appropriate data.
    RubyClass threadClass =
        runtime.defineClass(
            "Thread", runtime.getObject(), ObjectAllocator.NOT_ALLOCATABLE_ALLOCATOR);
    runtime.setThread(threadClass);

    threadClass.index = ClassIndex.THREAD;
    threadClass.setReifiedClass(RubyThread.class);

    threadClass.defineAnnotatedMethods(RubyThread.class);

    RubyThread rubyThread = new RubyThread(runtime, threadClass);
    // TODO: need to isolate the "current" thread from class creation
    rubyThread.threadImpl = new NativeThread(rubyThread, Thread.currentThread());
    runtime.getThreadService().setMainThread(Thread.currentThread(), rubyThread);

    // set to default thread group
    runtime.getDefaultThreadGroup().addDirectly(rubyThread);

    threadClass.setMarshal(ObjectMarshal.NOT_MARSHALABLE_MARSHAL);

    return threadClass;
  }
コード例 #2
0
ファイル: RubyTime.java プロジェクト: rizkyrukmana/jruby
  public static RubyClass createTimeClass(Ruby runtime) {
    RubyClass timeClass = runtime.defineClass("Time", runtime.getObject(), TIME_ALLOCATOR);

    timeClass.index = ClassIndex.TIME;
    timeClass.setReifiedClass(RubyTime.class);

    runtime.setTime(timeClass);

    timeClass.includeModule(runtime.getComparable());

    timeClass.defineAnnotatedMethods(RubyTime.class);

    return timeClass;
  }
コード例 #3
0
ファイル: RubyEncoding.java プロジェクト: isaiah/jruby
  public static RubyClass createEncodingClass(Ruby runtime) {
    RubyClass encodingc =
        runtime.defineClass(
            "Encoding", runtime.getObject(), ObjectAllocator.NOT_ALLOCATABLE_ALLOCATOR);
    runtime.setEncoding(encodingc);
    encodingc.index = ClassIndex.ENCODING;
    encodingc.setReifiedClass(RubyEncoding.class);
    encodingc.kindOf =
        new RubyModule.KindOf() {
          @Override
          public boolean isKindOf(IRubyObject obj, RubyModule type) {
            return obj instanceof RubyEncoding;
          }
        };

    encodingc.getSingletonClass().undefineMethod("allocate");
    encodingc.defineAnnotatedMethods(RubyEncoding.class);

    return encodingc;
  }
コード例 #4
0
ファイル: RubyMatchData.java プロジェクト: lopex/jruby
  public static RubyClass createMatchDataClass(Ruby runtime) {
    RubyClass matchDataClass =
        runtime.defineClass("MatchData", runtime.getObject(), MATCH_DATA_ALLOCATOR);
    runtime.setMatchData(matchDataClass);

    matchDataClass.index = ClassIndex.MATCHDATA;
    matchDataClass.setReifiedClass(RubyMatchData.class);

    runtime.defineGlobalConstant("MatchingData", matchDataClass);
    matchDataClass.kindOf =
        new RubyModule.KindOf() {
          @Override
          public boolean isKindOf(IRubyObject obj, RubyModule type) {
            return obj instanceof RubyMatchData;
          }
        };

    matchDataClass.getMetaClass().undefineMethod("new");
    matchDataClass.defineAnnotatedMethods(RubyMatchData.class);
    return matchDataClass;
  }
コード例 #5
0
ファイル: RubyTime.java プロジェクト: rizkyrukmana/jruby
 private static IRubyObject getEnvTimeZone(Ruby runtime) {
   RubyString tzVar = runtime.newString(TZ_STRING);
   RubyHash h = ((RubyHash) runtime.getObject().getConstant("ENV"));
   IRubyObject tz = h.op_aref(runtime.getCurrentContext(), tzVar);
   return tz;
 }