From: "naruse (Yui NARUSE)" Date: 2012-03-21T09:46:48+09:00 Subject: [ruby-core:43506] [ruby-trunk - Feature #6180] to_b for converting objects to a boolean value Issue #6180 has been updated by naruse (Yui NARUSE). BasicObject#! is optimized by YARV as following: % ruby -e'puts RubyVM::InstructionSequence.compile(%[!!foo]).disasm' == disasm: @>========== 0000 trace 1 ( 1) 0002 putself 0003 send :foo, 0, nil, 24, 0009 opt_not 0011 opt_not 0013 leave % rb -e'puts RubyVM::InstructionSequence.compile(%[foo.to_b]).disasm' == disasm: @>========== 0000 trace 1 ( 1) 0002 putself 0003 send :foo, 0, nil, 24, 0009 send :to_b, 0, nil, 0, 0015 leave As showed above, its byte code is shorter than with new method. ---------------------------------------- Feature #6180: to_b for converting objects to a boolean value https://bugs.ruby-lang.org/issues/6180#change-24987 Author: AaronLasseigne (Aaron Lasseigne) Status: Open Priority: Normal Assignee: Category: Target version: When a boolean return value is required it has become common practice is to use "!!" to convert the object. It would be more consistent to provide a "to_b" method on Object. -- http://bugs.ruby-lang.org/