From: aycabta@... Date: 2017-12-01T17:34:59+00:00 Subject: [ruby-core:84039] [Ruby trunk Feature#12753] Useful operator to check bit-flag is true or false Issue #12753 has been updated by aycabta (ayca bta). Hi @naruse, matz said below. matz (Yukihiro Matsumoto) wrote: > I vote for `allbit?`, `anybit?` and `nobit?`. I am not sure about plurality though. For your action, as you know, [Dir.exists?](https://bugs.ruby-lang.org/projects/ruby-trunk/repository/revisions/60974/entry/dir.c#L3085) and [File.exists?](https://bugs.ruby-lang.org/projects/ruby-trunk/repository/revisions/60974/entry/file.c#L1676) are deprecated. What do you think about this? ---------------------------------------- Feature #12753: Useful operator to check bit-flag is true or false https://bugs.ruby-lang.org/issues/12753#change-68126 * Author: tagomoris (Satoshi TAGOMORI) * Status: Assigned * Priority: Normal * Assignee: matz (Yukihiro Matsumoto) * Target version: 2.5 ---------------------------------------- Ruby's 0 is truthy value. It's useful for many cases, but it's confusing and I made many bugs when I'm writing code to handle binary data, because my thought is almost same with one to write C code in such situation. ```ruby n = get_integer_value if n & 0b10100000 # code for the case when flag is true else # never comes here :( end ``` IMO it's very useful to have methods for such use-cases, like `#and?` and `#xor?` (`#or?` looks not so useful... I can't imagine the use case of this operator, but it's better to have for consistency). ```ruby n = get_integer_value case when n.and?(0b10000000) # negative signed char when n.and?(0b01110000) # large positive else # small positive end ``` -- https://bugs.ruby-lang.org/ Unsubscribe: