[ruby-core:78378] Improving Ruby Bitwise Operations
From:
RRRoy BBBean <rrroybbbean@...>
Date:
2016-11-26 19:31:07 UTC
List:
ruby-core #78378
There is a ruby gem for bitwise operations, by Kenn Ejima, although it has not been updated in 4 years. https://rubygems.org/gems/bitwise https://github.com/kenn/bitwise I believe that the better approach for Ruby Bitwise Operations is to "dust-off" this "bitwise" gem and add whatever functionality is needed. That might include a ".mask" method, which returns true (if any resulting bit is 1) or false (if all resulting bits are 0). Such a method would bridge bitwise operations and Ruby's true/false. I further believe that having zero (integer, real, complex) be truthy is the correct behavior, which Ruby already implements. Note that Ruby currently provides ".zero?" and ".nonzero?" methods for numeric types. Although the return values are inconsistent between Integer, Real and Complex, they do return values which are behave correctly (as truthy or falsey). BEGIN CRITICAL If anything needs to be changed in the Ruby core, it is to make the results of ".zero?" and ".nonzero?" be consistently either true or false for all numeric values. Such a change would nicely map bitwise operations to Ruby true and false. END CRITICAL Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe> <http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>