Wroclove.rb - JRuby vs. Rubinius

Wroclove.rb - JRuby vs. Rubinius

Fighting for the Rubinius side

B012094b37ab6946c44eaa41d7828478?s=128

Dirkjan Bussink

March 14, 2012
Tweet

Transcript

  1. Dirkjan Bussink http://github.com/dbussink @dbussink

  2. None
  3. None
  4. REMOVED

  5. @JRubyMethod(name = {"collect", "map"}, compat = CompatVersion.RUBY1_8) public static IRubyObject

    collect(ThreadContext context, IRubyObject self, final Block block) { final Ruby runtime = context.getRuntime(); final RubyArray result = runtime.newArray(); if (block.isGiven()) { callEach(runtime, context, self, block.arity(), new BlockCallback() { public IRubyObject call(ThreadContext ctx, IRubyObject[] largs, Block blk) { IRubyObject larg = checkArgs(runtime, largs); IRubyObject value = block.yield(ctx, larg); synchronized (result) { result.append(value); } return runtime.getNil(); } }); } else { callEach(runtime, context, self, Arity.ONE_ARGUMENT, new AppendBlockCallback(runtime, result)); } return result; }
  6. def collect if block_given? ary = [] each do |*o|

    ary << yield(*o) end ary else to_enum :collect end end
  7. None
  8. > (x . xs) = [1, 2, 3] [1, 2,

    3] > x 1 > xs [2, 3]
  9. 1 patch == commit access