https://redmine.ruby-lang.org/https://redmine.ruby-lang.org/favicon.ico?17113305112016-09-12T07:11:33ZRuby Issue Tracking SystemRuby master - Feature #12753: Useful operator to check bit-flag is true or falsehttps://redmine.ruby-lang.org/issues/12753?journal_id=604852016-09-12T07:11:33Zshyouhei (Shyouhei Urabe)shyouhei@ruby-lang.org
<ul><li><strong>Description</strong> updated (<a title="View differences" href="/journals/60485/diff?detail_id=42430">diff</a>)</li></ul> Ruby master - Feature #12753: Useful operator to check bit-flag is true or falsehttps://redmine.ruby-lang.org/issues/12753?journal_id=616782016-11-25T07:28:38Zmatz (Yukihiro Matsumoto)matz@ruby.or.jp
<ul></ul><p>I understand the demand. But <code>and?</code> is an unacceptable name.<br>
Any idea?</p>
<p>Matz.</p> Ruby master - Feature #12753: Useful operator to check bit-flag is true or falsehttps://redmine.ruby-lang.org/issues/12753?journal_id=616792016-11-25T07:28:57Znaruse (Yui NARUSE)naruse@airemix.jp
<ul></ul><p>What about <code>bittest?</code></p> Ruby master - Feature #12753: Useful operator to check bit-flag is true or falsehttps://redmine.ruby-lang.org/issues/12753?journal_id=616842016-11-25T07:45:05Zmatz (Yukihiro Matsumoto)matz@ruby.or.jp
<ul></ul><p><code>bittest?</code> sounds reasonable. Accepted.</p>
<p>Matz.</p> Ruby master - Feature #12753: Useful operator to check bit-flag is true or falsehttps://redmine.ruby-lang.org/issues/12753?journal_id=616892016-11-25T07:59:22Zherwinw (Herwin Quarantainenet)herwin@quarantainenet.nl
<ul></ul><p>I can't say the usage of <code>bittest?</code> is directly clear to me. Does it test if resulting integer is not equal to <code>0</code>? And would we have to use it this way?</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="k">if</span> <span class="p">(</span><span class="n">n</span> <span class="o">&</span> <span class="mb">0b10100000</span><span class="p">).</span><span class="nf">bittest?</span>
</code></pre>
<p>I think a name like <code>Integer#binary_and?</code> (maybe shortened to <code>#binand?</code>) would result in cleaner code</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="k">if</span> <span class="n">n</span><span class="p">.</span><span class="nf">binary_and?</span><span class="p">(</span><span class="mb">0b10100000</span><span class="p">)</span>
</code></pre>
<p>Of course this would require several other implementations as well, for all other binary operators</p> Ruby master - Feature #12753: Useful operator to check bit-flag is true or falsehttps://redmine.ruby-lang.org/issues/12753?journal_id=617312016-11-25T15:01:02Znaruse (Yui NARUSE)naruse@airemix.jp
<ul></ul><p>Herwin Quarantainenet wrote:</p>
<blockquote>
<p>I can't say the usage of <code>bittest?</code> is directly clear to me. Does it test if resulting integer is not equal to <code>0</code>? And would we have to use it this way?</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="k">if</span> <span class="p">(</span><span class="n">n</span> <span class="o">&</span> <span class="mb">0b10100000</span><span class="p">).</span><span class="nf">bittest?</span>
</code></pre>
</blockquote>
<p>Like</p>
<pre><code class="ruby syntaxhl" data-language="ruby"> <span class="k">if</span> <span class="n">n</span><span class="p">.</span><span class="nf">bittest?</span><span class="p">(</span><span class="mb">0b10100000</span><span class="p">)</span>
</code></pre>
<blockquote>
<p>I think a name like <code>Integer#binary_and?</code> (maybe shortened to <code>#binand?</code>) would result in cleaner code</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="k">if</span> <span class="n">n</span><span class="p">.</span><span class="nf">binary_and?</span><span class="p">(</span><span class="mb">0b10100000</span><span class="p">)</span>
</code></pre>
<p>Of course this would require several other implementations as well, for all other binary operators</p>
</blockquote>
<p>There's two AND, bitwise and logical.<br>
Therefore it can be <code>bit_and?</code>, but there's no reason to write logical AND as a method, which can be written with <code>&&</code>.</p> Ruby master - Feature #12753: Useful operator to check bit-flag is true or falsehttps://redmine.ruby-lang.org/issues/12753?journal_id=617522016-11-26T14:51:06Zherwin (Herwin W)
<ul></ul><pre><code class="ruby syntaxhl" data-language="ruby"><span class="k">if</span> <span class="n">n</span><span class="p">.</span><span class="nf">bittest?</span><span class="p">(</span><span class="mb">0b10100000</span><span class="p">)</span>
</code></pre>
<p>If I encountered that code without having the context of this case, I wouldn't know what what the equivalent behaviour would be:</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="k">if</span> <span class="n">n</span> <span class="o">&</span> <span class="mb">0b10100000</span> <span class="o">!=</span> <span class="mi">0</span> <span class="c1">#=> Is at least one bit of the argument set?</span>
<span class="k">if</span> <span class="n">n</span> <span class="o">&</span> <span class="mb">0b10100000</span> <span class="o">==</span> <span class="mb">0b10100000</span> <span class="c1">#=> Are all the bits of the argument set?</span>
</code></pre>
<blockquote>
<p>There's two AND, bitwise and logical.<br>
Therefore it can be bit_and?, but there's no reason to write logical AND as a method, which can be written with &&.</p>
</blockquote>
<p>I was actually thinking about the other bitwise/binary operators here, like <code>|</code> and <code>^</code></p> Ruby master - Feature #12753: Useful operator to check bit-flag is true or falsehttps://redmine.ruby-lang.org/issues/12753?journal_id=618202016-12-01T08:33:44Znaruse (Yui NARUSE)naruse@airemix.jp
<ul></ul><p>Herwin W wrote:</p>
<blockquote>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="k">if</span> <span class="n">n</span><span class="p">.</span><span class="nf">bittest?</span><span class="p">(</span><span class="mb">0b10100000</span><span class="p">)</span>
</code></pre>
<p>If I encountered that code without having the context of this case, I wouldn't know what what the equivalent behaviour would be:</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="k">if</span> <span class="n">n</span> <span class="o">&</span> <span class="mb">0b10100000</span> <span class="o">!=</span> <span class="mi">0</span> <span class="c1">#=> Is at least one bit of the argument set?</span>
<span class="k">if</span> <span class="n">n</span> <span class="o">&</span> <span class="mb">0b10100000</span> <span class="o">==</span> <span class="mb">0b10100000</span> <span class="c1">#=> Are all the bits of the argument set?</span>
</code></pre>
</blockquote>
<p>Above one.</p>
<blockquote>
<blockquote>
<p>There's two AND, bitwise and logical.<br>
Therefore it can be bit_and?, but there's no reason to write logical AND as a method, which can be written with &&.</p>
</blockquote>
<p>I was actually thinking about the other bitwise/binary operators here, like <code>|</code> and <code>^</code></p>
</blockquote>
<p>I can't show a use case of <code>|</code>.<br>
<code>^</code> is maybe useful but the name is difficult.</p> Ruby master - Feature #12753: Useful operator to check bit-flag is true or falsehttps://redmine.ruby-lang.org/issues/12753?journal_id=618212016-12-01T09:16:39Zshugo (Shugo Maeda)
<ul></ul><p>Yui NARUSE wrote:</p>
<blockquote>
<p>Herwin W wrote:</p>
<blockquote>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="k">if</span> <span class="n">n</span><span class="p">.</span><span class="nf">bittest?</span><span class="p">(</span><span class="mb">0b10100000</span><span class="p">)</span>
</code></pre>
<p>If I encountered that code without having the context of this case, I wouldn't know what what the equivalent behaviour would be:</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="k">if</span> <span class="n">n</span> <span class="o">&</span> <span class="mb">0b10100000</span> <span class="o">!=</span> <span class="mi">0</span> <span class="c1">#=> Is at least one bit of the argument set?</span>
<span class="k">if</span> <span class="n">n</span> <span class="o">&</span> <span class="mb">0b10100000</span> <span class="o">==</span> <span class="mb">0b10100000</span> <span class="c1">#=> Are all the bits of the argument set?</span>
</code></pre>
</blockquote>
<p>Above one.</p>
</blockquote>
<p>IBM InfoSphere and MS FoxPro have BITTEST(), but its second argument is the bit position<br>
to be tested.</p>
<p><a href="http://www.ibm.com/support/knowledgecenter/SSZJPZ_11.3.0/com.ibm.swg.im.iis.ds.basic.doc/topics/r_dsbasic_BITTEST_function.html" class="external">http://www.ibm.com/support/knowledgecenter/SSZJPZ_11.3.0/com.ibm.swg.im.iis.ds.basic.doc/topics/r_dsbasic_BITTEST_function.html</a><br>
<a href="https://msdn.microsoft.com/en-us/library/aa977348(v=vs.71).aspx" class="external">https://msdn.microsoft.com/en-us/library/aa977348(v=vs.71).aspx</a></p>
<p>This behavior seems to fit the name bittest, compared to the proposed one.</p> Ruby master - Feature #12753: Useful operator to check bit-flag is true or falsehttps://redmine.ruby-lang.org/issues/12753?journal_id=618222016-12-01T09:21:56Zshugo (Shugo Maeda)
<ul></ul><p>Shugo Maeda wrote:</p>
<blockquote>
<p>IBM InfoSphere and MS FoxPro have BITTEST(), but its second argument is the bit position<br>
to be tested.</p>
<p><a href="http://www.ibm.com/support/knowledgecenter/SSZJPZ_11.3.0/com.ibm.swg.im.iis.ds.basic.doc/topics/r_dsbasic_BITTEST_function.html" class="external">http://www.ibm.com/support/knowledgecenter/SSZJPZ_11.3.0/com.ibm.swg.im.iis.ds.basic.doc/topics/r_dsbasic_BITTEST_function.html</a><br>
<a href="https://msdn.microsoft.com/en-us/library/aa977348(v=vs.71).aspx" class="external">https://msdn.microsoft.com/en-us/library/aa977348(v=vs.71).aspx</a></p>
<p>This behavior seems to fit the name bittest, compared to the proposed one.</p>
</blockquote>
<p>I didn't mean to propose this behavior.<br>
I just meant to point out that <code>bittest?</code> may not be suitable for the proposed behavior.</p> Ruby master - Feature #12753: Useful operator to check bit-flag is true or falsehttps://redmine.ruby-lang.org/issues/12753?journal_id=666972017-09-15T16:31:58Ztagomoris (Satoshi Tagomori)tagomoris@gmail.com
<ul></ul><p>How about <code>bitmask_test?</code> or <code>bitflag_test?</code></p>
<p>shugo (Shugo Maeda) wrote:</p>
<blockquote>
<p>Shugo Maeda wrote:</p>
<blockquote>
<p>IBM InfoSphere and MS FoxPro have BITTEST(), but its second argument is the bit position<br>
to be tested.</p>
<p><a href="http://www.ibm.com/support/knowledgecenter/SSZJPZ_11.3.0/com.ibm.swg.im.iis.ds.basic.doc/topics/r_dsbasic_BITTEST_function.html" class="external">http://www.ibm.com/support/knowledgecenter/SSZJPZ_11.3.0/com.ibm.swg.im.iis.ds.basic.doc/topics/r_dsbasic_BITTEST_function.html</a><br>
<a href="https://msdn.microsoft.com/en-us/library/aa977348(v=vs.71).aspx" class="external">https://msdn.microsoft.com/en-us/library/aa977348(v=vs.71).aspx</a></p>
<p>This behavior seems to fit the name bittest, compared to the proposed one.</p>
</blockquote>
<p>I didn't mean to propose this behavior.<br>
I just meant to point out that <code>bittest?</code> may not be suitable for the proposed behavior.</p>
</blockquote> Ruby master - Feature #12753: Useful operator to check bit-flag is true or falsehttps://redmine.ruby-lang.org/issues/12753?journal_id=673362017-10-19T06:49:23Zakr (Akira Tanaka)akr@fsij.org
<ul></ul><p>How about Integer#has_allbits?(n), Integer#has_somebits?(n) and Integer#has_nobits?(n) ?</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="k">class</span> <span class="nc">Integer</span>
<span class="k">def</span> <span class="nf">has_allbits?</span><span class="p">(</span><span class="n">n</span><span class="p">)</span> <span class="nb">self</span> <span class="o">&</span> <span class="n">n</span> <span class="o">==</span> <span class="n">n</span> <span class="k">end</span>
<span class="k">def</span> <span class="nf">has_somebits?</span><span class="p">(</span><span class="n">n</span><span class="p">)</span> <span class="nb">self</span> <span class="o">&</span> <span class="n">n</span> <span class="o">!=</span> <span class="mi">0</span> <span class="k">end</span>
<span class="k">def</span> <span class="nf">has_nobits?</span><span class="p">(</span><span class="n">n</span><span class="p">)</span> <span class="nb">self</span> <span class="o">&</span> <span class="n">n</span> <span class="o">==</span> <span class="mi">0</span> <span class="k">end</span>
<span class="k">end</span>
</code></pre> Ruby master - Feature #12753: Useful operator to check bit-flag is true or falsehttps://redmine.ruby-lang.org/issues/12753?journal_id=673392017-10-19T06:58:18Zmatz (Yukihiro Matsumoto)matz@ruby.or.jp
<ul></ul><p><code>has_*</code> is not acceptable. It's not compatible with other method names.<br>
I vote for <code>allbit?</code>, <code>anybit?</code> and <code>nobit?</code>. I am not sure about plurality though.</p>
<p>Matz.</p> Ruby master - Feature #12753: Useful operator to check bit-flag is true or falsehttps://redmine.ruby-lang.org/issues/12753?journal_id=673402017-10-19T07:11:05Zknu (Akinori MUSHA)knu@ruby-lang.org
<ul></ul><p>Speaking of plurality, what about:</p>
<p><code>a.bit?(b)</code> → <code>a & b != 0</code><br>
<code>a.bits?(b)</code> → <code>a & b == b</code></p> Ruby master - Feature #12753: Useful operator to check bit-flag is true or falsehttps://redmine.ruby-lang.org/issues/12753?journal_id=673522017-10-19T10:13:12Zphluid61 (Matthew Kerwin)matthew@kerwin.net.au
<ul></ul><p>I think plural makes most sense:</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="n">a</span><span class="p">.</span><span class="nf">allbits?</span> <span class="n">b</span> <span class="c1">#→ a & b == b</span>
<span class="n">a</span><span class="p">.</span><span class="nf">anybits?</span> <span class="n">b</span> <span class="c1">#→ a & b != 0</span>
<span class="n">a</span><span class="p">.</span><span class="nf">nobits?</span> <span class="n">b</span> <span class="c1">#→ a & b == 0</span>
</code></pre>
<p>It introduces a strange paradox, though:</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="n">a</span><span class="p">.</span><span class="nf">allbits?</span> <span class="mi">0</span> <span class="c1">#→ true</span>
<span class="n">a</span><span class="p">.</span><span class="nf">nobits?</span> <span class="mi">0</span> <span class="c1">#→ true</span>
</code></pre> Ruby master - Feature #12753: Useful operator to check bit-flag is true or falsehttps://redmine.ruby-lang.org/issues/12753?journal_id=680982017-12-01T00:31:11Zaycabta (aycabta .)aycabta@gmail.com
<ul></ul><p>phluid61 (Matthew Kerwin) wrote:</p>
<blockquote>
<p>It introduces a strange paradox, though:</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="n">a</span><span class="p">.</span><span class="nf">allbits?</span> <span class="mi">0</span> <span class="c1">#→ true</span>
<span class="n">a</span><span class="p">.</span><span class="nf">nobits?</span> <span class="mi">0</span> <span class="c1">#→ true</span>
</code></pre>
</blockquote>
<p>I discussed it with <a class="user active user-mention" href="https://redmine.ruby-lang.org/users/12374">@watson1978 (Shizuo Fujita)</a> (Shizuo Fujita). We guess the behavior is not strange.</p>
<p>The allbits? means "The receiver checks that all standing bits of the argument don't sit on itself".</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="n">a</span><span class="p">.</span><span class="nf">allbits?</span> <span class="mi">0</span> <span class="c1">#→ true</span>
</code></pre>
<p>In this case, "all standing bits of the argument don't sit on the receiver " because "all standing bits of argument" is nothing. So it returns true. I think this is correct. If I have to choose a word, it's reasonable specification.</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="n">a</span><span class="p">.</span><span class="nf">nobits?</span> <span class="mi">0</span> <span class="c1">#→ true</span>
</code></pre>
<p>I think this is correct in the same way.</p> Ruby master - Feature #12753: Useful operator to check bit-flag is true or falsehttps://redmine.ruby-lang.org/issues/12753?journal_id=681172017-12-01T16:26:28Znaruse (Yui NARUSE)naruse@airemix.jp
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Assigned</i></li><li><strong>Assignee</strong> set to <i>matz (Yukihiro Matsumoto)</i></li><li><strong>Target version</strong> set to <i>2.5</i></li></ul><p>A patch is as follows:</p>
<pre><code class="diff syntaxhl" data-language="diff"><span class="gh">diff --git a/numeric.c b/numeric.c
index 1858113c09..511155a3ac 100644
</span><span class="gd">--- a/numeric.c
</span><span class="gi">+++ b/numeric.c
</span><span class="p">@@ -3209,6 +3209,45 @@</span> int_even_p(VALUE num)
return Qfalse;
}
<span class="gi">+/*
+ * call-seq:
+ * int.allbits?(mask) -> true or false
+ *
+ * Returns +true+ if all bits of <code>+int+ & +mask+</code> is 1.
+ */
+
+static VALUE
+int_allbits_p(VALUE num, VALUE mask)
+{
+ return rb_int_equal(rb_int_and(num, mask), mask);
+}
+
+/*
+ * call-seq:
+ * int.anybits?(mask) -> true or false
+ *
+ * Returns +true+ if any bits of <code>+int+ & +mask+</code> is 1.
+ */
+
+static VALUE
+int_anybits_p(VALUE num, VALUE mask)
+{
+ return num_zero_p(rb_int_and(num, mask)) ? Qfalse : Qtrue;
+}
+
+/*
+ * call-seq:
+ * int.nobits?(mask) -> true or false
+ *
+ * Returns +true+ if no bits of <code>+int+ & +mask+</code> is 1.
+ */
+
+static VALUE
+int_nobits_p(VALUE num, VALUE mask)
+{
+ return num_zero_p(rb_int_and(num, mask));
+}
+
</span> /*
* Document-method: Integer#succ
* Document-method: Integer#next
<span class="p">@@ -5396,6 +5435,9 @@</span> Init_Numeric(void)
rb_define_method(rb_cInteger, "integer?", int_int_p, 0);
rb_define_method(rb_cInteger, "odd?", int_odd_p, 0);
rb_define_method(rb_cInteger, "even?", int_even_p, 0);
<span class="gi">+ rb_define_method(rb_cInteger, "allbits?", int_allbits_p, 1);
+ rb_define_method(rb_cInteger, "anybits?", int_anybits_p, 1);
+ rb_define_method(rb_cInteger, "nobits?", int_nobits_p, 1);
</span> rb_define_method(rb_cInteger, "upto", int_upto, 1);
rb_define_method(rb_cInteger, "downto", int_downto, 1);
rb_define_method(rb_cInteger, "times", int_dotimes, 0);
<span class="gh">diff --git a/test/ruby/test_integer_comb.rb b/test/ruby/test_integer_comb.rb
index 80d08cac04..1ad13dd31b 100644
</span><span class="gd">--- a/test/ruby/test_integer_comb.rb
</span><span class="gi">+++ b/test/ruby/test_integer_comb.rb
</span><span class="p">@@ -457,6 +457,30 @@</span> def test_even_odd
}
end
<span class="gi">+ def test_allbits_p
+ VS.each {|a|
+ VS.each {|b|
+ assert_equal((a & b) == b, a.allbits?(b), "(#{a}).allbits?(#{b}")
+ }
+ }
+ end
+
+ def test_anybits_p
+ VS.each {|a|
+ VS.each {|b|
+ assert_equal((a & b) != 0, a.anybits?(b), "(#{a}).anybits?(#{b}")
+ }
+ }
+ end
+
+ def test_nobits_p
+ VS.each {|a|
+ VS.each {|b|
+ assert_equal((a & b) == 0, a.nobits?(b), "(#{a}).nobits?(#{b}")
+ }
+ }
+ end
+
</span> def test_to_s
2.upto(36) {|radix|
VS.each {|a|
</code></pre> Ruby master - Feature #12753: Useful operator to check bit-flag is true or falsehttps://redmine.ruby-lang.org/issues/12753?journal_id=681262017-12-01T17:34:57Zaycabta (aycabta .)aycabta@gmail.com
<ul></ul><p>Hi <a class="user active user-mention" href="https://redmine.ruby-lang.org/users/5">@naruse (Yui NARUSE)</a>, matz said below.</p>
<p>matz (Yukihiro Matsumoto) wrote:</p>
<blockquote>
<p>I vote for <code>allbit?</code>, <code>anybit?</code> and <code>nobit?</code>. I am not sure about plurality though.</p>
</blockquote>
<p>For your action, as you know, <a href="https://bugs.ruby-lang.org/projects/ruby-trunk/repository/revisions/60974/entry/dir.c#L3085" class="external">Dir.exists?</a> and <a href="https://bugs.ruby-lang.org/projects/ruby-trunk/repository/revisions/60974/entry/file.c#L1676" class="external">File.exists?</a> are deprecated. What do you think about this?</p> Ruby master - Feature #12753: Useful operator to check bit-flag is true or falsehttps://redmine.ruby-lang.org/issues/12753?journal_id=681292017-12-01T20:56:26Zphluid61 (Matthew Kerwin)matthew@kerwin.net.au
<ul></ul><p>aycabta (ayca bta) wrote:</p>
<blockquote>
<p>Hi <a class="user active user-mention" href="https://redmine.ruby-lang.org/users/5">@naruse (Yui NARUSE)</a>, matz said below.</p>
<p>matz (Yukihiro Matsumoto) wrote:</p>
<blockquote>
<p>I vote for <code>allbit?</code>, <code>anybit?</code> and <code>nobit?</code>. I am not sure about plurality though.</p>
</blockquote>
<p>For your action, as you know, <a href="https://bugs.ruby-lang.org/projects/ruby-trunk/repository/revisions/60974/entry/dir.c#L3085" class="external">Dir.exists?</a> and <a href="https://bugs.ruby-lang.org/projects/ruby-trunk/repository/revisions/60974/entry/file.c#L1676" class="external">File.exists?</a> are deprecated. What do you think about this?</p>
</blockquote>
<p>exist/exists is tense, bit/bits is plurality, so it is unrelated.</p> Ruby master - Feature #12753: Useful operator to check bit-flag is true or falsehttps://redmine.ruby-lang.org/issues/12753?journal_id=681322017-12-01T22:34:01Zaycabta (aycabta .)aycabta@gmail.com
<ul></ul><p>phluid61 (Matthew Kerwin) wrote:</p>
<blockquote>
<p>exist/exists is tense, bit/bits is plurality, so it is unrelated.</p>
</blockquote>
<p>Oh, thank you...I understand.</p> Ruby master - Feature #12753: Useful operator to check bit-flag is true or falsehttps://redmine.ruby-lang.org/issues/12753?journal_id=682092017-12-06T17:10:44Zaycabta (aycabta .)aycabta@gmail.com
<ul></ul><p>In Ruby 2.5, Ripper::Lexer::State is introduced:<br>
<a href="https://bugs.ruby-lang.org/projects/ruby-trunk/repository/revisions/60945/entry/ext/ripper/lib/ripper/lexer.rb#L49" class="external">https://bugs.ruby-lang.org/projects/ruby-trunk/repository/revisions/60945/entry/ext/ripper/lib/ripper/lexer.rb#L49</a></p>
<p>It is for lex_state of parse.y, and has #& and #| for bit operations with lex_state_bits:<br>
<a href="https://bugs.ruby-lang.org/projects/ruby-trunk/repository/revisions/60945/entry/parse.y#L78" class="external">https://bugs.ruby-lang.org/projects/ruby-trunk/repository/revisions/60945/entry/parse.y#L78</a></p>
<p>RDoc uses it:<br>
<a href="https://bugs.ruby-lang.org/projects/ruby-trunk/repository/revisions/60945/entry/lib/rdoc/parser/ripper_state_lex.rb#L321" class="external">https://bugs.ruby-lang.org/projects/ruby-trunk/repository/revisions/60945/entry/lib/rdoc/parser/ripper_state_lex.rb#L321</a></p>
<p>If Integer#allbit? is implemented at 2.5, it's good for Ripper::Lexer::State and I'll use it for RDoc on 2.5.</p> Ruby master - Feature #12753: Useful operator to check bit-flag is true or falsehttps://redmine.ruby-lang.org/issues/12753?journal_id=683162017-12-12T09:12:26Znaruse (Yui NARUSE)naruse@airemix.jp
<ul><li><strong>Status</strong> changed from <i>Assigned</i> to <i>Closed</i></li></ul><p>Applied in changeset trunk|r61147.</p>
<hr>
<p>Integer#allbits?, Integer#anybits?, Integer#nobits? [Feature <a class="issue tracker-2 status-5 priority-4 priority-default closed" title="Feature: Useful operator to check bit-flag is true or false (Closed)" href="https://redmine.ruby-lang.org/issues/12753">#12753</a>]</p> Ruby master - Feature #12753: Useful operator to check bit-flag is true or falsehttps://redmine.ruby-lang.org/issues/12753?journal_id=684742017-12-17T18:21:05Zmarcandre (Marc-Andre Lafortune)marcandre-ruby-core@marc-andre.ca
<ul></ul><p>When writing specs, I discovered that coercion was failing for allbits.</p>
<p>I modified all three methods to apply coercion with <code>to_int</code> if needed.</p>