@JRubyMethod public IRubyObject length(ThreadContext context) { return context.runtime.newFixnum(this.table.size()); }
@JRubyMethod public IRubyObject each(ThreadContext context, Block block) { for (Map.Entry<String, RubyFieldDescriptor> entry : fieldDefMap.entrySet()) { block.yield(context, entry.getValue()); } return context.runtime.getNil(); }
@JRubyMethod public IRubyObject each(ThreadContext context, Block block) { for (IRubyObject key : table.keySet()) { block.yieldSpecific(context, key, table.get(key)); } return context.runtime.getNil(); }
@JRubyMethod(rest = true) public static IRubyObject java_implements(IRubyObject recv, IRubyObject[] args) { // empty stub for now return recv.getRuntime().getNil(); }
@JRubyMethod(name = {"index", "find_index"}) public IRubyObject index(ThreadContext context, Block block) { Ruby runtime = context.runtime; if (!block.isGiven()) return enumeratorize(runtime, this, "index"); for (int i = 0; i < realLength; i++) { if (block.yield(context, eltOk(i)).isTrue()) return runtime.newFixnum(i); } return runtime.getNil(); }
@JRubyMethod(module = true) public static IRubyObject yield_self(ThreadContext context, IRubyObject recv, Block block) { if (block.isGiven()) { return block.yield(context, recv); } else { SizeFn enumSizeFn = RubyArray.newArray(context.runtime, context.nil).enumLengthFn(); return RubyEnumerator.enumeratorizeWithSize(context, recv, "yield_self", enumSizeFn); } }
/** rb_ary_cycle * */ @JRubyMethod(name = "cycle") public IRubyObject cycle(ThreadContext context, IRubyObject arg, Block block) { if (arg.isNil()) return cycle(context, block); if (!block.isGiven()) return enumeratorize(context.runtime, this, "cycle", arg); long times = RubyNumeric.num2long(arg); if (times <= 0) return context.runtime.getNil(); return cycleCommon(context, times, block); }
@JRubyMethod(required = 3, optional = 1) public IRubyObject required(ThreadContext context, IRubyObject[] args) { IRubyObject typeClass = context.runtime.getNil(); if (args.length > 3) typeClass = args[3]; msgdefAddField(context, "required", args[0], args[1], args[2], typeClass); return context.runtime.getNil(); }
@JRubyMethod(name = "add_enum") public IRubyObject addEnum(ThreadContext context, IRubyObject name, Block block) { RubyEnumDescriptor enumDef = (RubyEnumDescriptor) cEnumDescriptor.newInstance(context, Block.NULL_BLOCK); IRubyObject ctx = cEnumBuilderContext.newInstance(context, enumDef, Block.NULL_BLOCK); enumDef.setName(context, name); if (block.isGiven()) { if (block.arity() == Arity.ONE_ARGUMENT) { block.yield(context, ctx); } else { Binding binding = block.getBinding(); binding.setSelf(ctx); block.yieldSpecific(context); } } this.pendingList.add(enumDef); return context.runtime.getNil(); }
@JRubyMethod(optional = 1) public IRubyObject each_line(ThreadContext context, IRubyObject[] args, Block block) { if (!block.isGiven()) return RubyEnumerator.enumeratorize(context.runtime, this, "each_line", args); return each(context, args, block); }
@JRubyMethod(meta = true) public static IRubyObject resolve(ThreadContext context, IRubyObject recv, IRubyObject name) { RubyEnumDescriptor rubyEnumDescriptorescriptor = (RubyEnumDescriptor) getDescriptor(context, recv); Descriptors.EnumDescriptor descriptor = rubyEnumDescriptorescriptor.getDescriptor(); Descriptors.EnumValueDescriptor value = descriptor.findValueByName(name.asJavaString()); if (value == null) return context.runtime.getNil(); return context.runtime.newFixnum(value.getNumber()); }
/** rb_ary_frozen_p * */ @JRubyMethod(name = "frozen?") @Override public RubyBoolean frozen_p(ThreadContext context) { return context.runtime.newBoolean(isFrozen() || (flags & TMPLOCK_ARR_F) != 0); }
@JRubyMethod(name = "match", compat = RUBY1_9, reads = BACKREF) public IRubyObject match19(ThreadContext context, IRubyObject pattern, Block block) { IRubyObject result = getPattern(pattern).callMethod(context, "match", this); return block.isGiven() && !result.isNil() ? block.yield(context, result) : result; }
@JRubyMethod public IRubyObject each(ThreadContext context, Block block) { Ruby runtime = context.runtime; for (Descriptors.EnumValueDescriptor enumValueDescriptor : descriptor.getValues()) { block.yield(context, runtime.newArray(runtime.newSymbol(enumValueDescriptor.getName()), runtime.newFixnum(enumValueDescriptor.getNumber()))); } return runtime.getNil(); }
/** rb_ary_cycle * */ @JRubyMethod(name = "cycle") public IRubyObject cycle(ThreadContext context, IRubyObject arg, Block block) { if (arg.isNil()) return cycle(context, block); if (!block.isGiven()) return enumeratorizeWithSize(context, this, "cycle", new IRubyObject[] {arg}, cycleSizeFn(context)); long times = RubyNumeric.num2long(arg); if (times <= 0) return context.nil; return cycleCommon(context, times, block); }
@JRubyMethod public IRubyObject each_char(final ThreadContext context, final Block block) { if (!block.isGiven()) return enumeratorize(context.runtime, this, "each_char"); IRubyObject c; while (!(c = getc(context)).isNil()) { block.yieldSpecific(context, c); } return this; }
/** rb_ary_cycle * */ @JRubyMethod(name = "cycle") public IRubyObject cycle(ThreadContext context, Block block) { if (!block.isGiven()) return enumeratorizeWithSize(context, this, "cycle", cycleSizeFn(context)); return cycleCommon(context, -1, block); }
@JRubyMethod(name = "==", required = 1) public IRubyObject op_equal(ThreadContext context, IRubyObject obj) { return context.runtime.newBoolean(this == obj || getAddress() == 0L && obj.isNil() || (obj instanceof Pointer && ((Pointer) obj).getAddress() == getAddress())); }
@JRubyMethod(required = 4, optional = 1) public IRubyObject map(ThreadContext context, IRubyObject[] args) { Ruby runtime = context.runtime; IRubyObject valueType = args[2]; IRubyObject number = args[3]; IRubyObject typeClass = args.length > 4 ? args[4] : context.runtime.getNil(); keyField.setName(context, runtime.newString("key")); keyField.setLabel(context, RubySymbol.newSymbol(runtime, "optional")); keyField.setNumber(context, runtime.newFixnum(1)); keyField.setType(context, keyType); mapentryDesc.addField(context, keyField); valueField.setName(context, runtime.newString("value")); valueField.setLabel(context, RubySymbol.newSymbol(runtime, "optional")); valueField.setNumber(context, runtime.newFixnum(2)); valueField.setType(context, valueType); if (! typeClass.isNil()) valueField.setSubmsgName(context, typeClass); mapentryDesc.addField(context, valueField); return runtime.getNil();
@JRubyMethod public IRubyObject linger(ThreadContext context) { final Ruby runtime = context.runtime; validateDataSize(runtime, data, 8); int[] linger = Option.unpackLinger(data); return runtime.newArray(runtime.newBoolean(linger[0] != 0), runtime.newFixnum(linger[1])); }