Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 96b264bf3e3a
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 146bbf54c0b5
Choose a head ref
  • 2 commits
  • 1 file changed
  • 2 contributors

Commits on Mar 15, 2018

  1. Add Integer#allbits?, Integer#anybits? and Integer#nobits?

    For more information, please see feature #12753.
    nomadium committed Mar 15, 2018

    Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    nomadium Miguel Landaeta
    Copy the full SHA
    1164852 View commit details
  2. Merge pull request #5087 from nomadium/add-ruby-2.5-integer-new-bitma…

    …sk-methods
    
    Add Integer#allbits?, Integer#anybits? and Integer#nobits?
    enebo authored Mar 15, 2018

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    146bbf5 View commit details
Showing with 19 additions and 0 deletions.
  1. +19 −0 core/src/main/java/org/jruby/RubyInteger.java
19 changes: 19 additions & 0 deletions core/src/main/java/org/jruby/RubyInteger.java
Original file line number Diff line number Diff line change
@@ -49,6 +49,7 @@
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.util.ByteList;
import org.jruby.util.TypeConverter;
import org.jruby.util.io.EncodingUtils;

import java.math.BigInteger;
@@ -604,6 +605,24 @@ private static long op_mod_two(ThreadContext context, RubyInteger self) {
return ((RubyInteger) sites(context).op_mod.call(context, self, self, RubyFixnum.two(context.runtime))).getLongValue();
}

@JRubyMethod(name = "allbits?")
public IRubyObject allbits_p(ThreadContext context, IRubyObject other) {
IRubyObject mask = TypeConverter.checkIntegerType(context, other);
return ((RubyInteger) op_and(context, mask)).op_equal(context, mask);
}

@JRubyMethod(name = "anybits?")
public IRubyObject anybits_p(ThreadContext context, IRubyObject other) {
IRubyObject mask = TypeConverter.checkIntegerType(context, other);
return ((RubyInteger) op_and(context, mask)).zero_p(context).isTrue() ? context.fals : context.tru;
}

@JRubyMethod(name = "nobits?")
public IRubyObject nobits_p(ThreadContext context, IRubyObject other) {
IRubyObject mask = TypeConverter.checkIntegerType(context, other);
return ((RubyInteger) op_and(context, mask)).zero_p(context);
}

@JRubyMethod(name = "pred")
public IRubyObject pred(ThreadContext context) {
return numFuncall(context, this, sites(context).op_minus, RubyFixnum.one(context.runtime));