private static IRubyObject countCommon(ThreadContext context, IRubyObject self, final Block block, Arity callbackArity) {
final Ruby runtime = context.runtime;
final int result[] = new int[] { 0 };
if (block.isGiven()) {
each(context, self, new JavaInternalBlockBody(runtime, context, "Enumerable#count", block.arity()) {
public IRubyObject yield(ThreadContext context, IRubyObject[] args) {
IRubyObject packedArg = packEnumValues(context.runtime, args);
if (block.yield(context, packedArg).isTrue()) result[0]++;
return runtime.getNil();
}
});
} else {
each(context, self, new JavaInternalBlockBody(runtime, context, "Enumerable#count", Arity.NO_ARGUMENTS) {
public IRubyObject yield(ThreadContext context, IRubyObject[] unusedValue) {
result[0]++;
return runtime.getNil();
}
});