[#78633] ruby/spec needs help from CRuby committers — Benoit Daloze <eregontp@...>
Currently, ruby/spec is maintained mostly by individuals and enjoys the
13 messages
2016/12/13
[#78963] Re: ruby/spec needs help from CRuby committers
— Urabe Shyouhei <shyouhei@...>
2017/01/04
I did ask attendees of last developer meeting to join this
[#78642] Re: ruby/spec needs help from CRuby committers
— Eric Wong <normalperson@...>
2016/12/14
Benoit Daloze <eregontp@gmail.com> wrote:
[ruby-core:78456] [Ruby trunk Feature#12752] Unpacking a value from a binary requires additional '.first'
From:
naruse@...
Date:
2016-12-01 13:49:10 UTC
List:
ruby-core #78456
Issue #12752 has been updated by Yui NARUSE.
Akinori MUSHA wrote:
> With a qualifier or multiple directives given, would it raise an ArgumentError or just go ahead with the process and only return the first value?
Just after processing the first value, it returns.
----------------------------------------
Feature #12752: Unpacking a value from a binary requires additional '.first'
https://bugs.ruby-lang.org/issues/12752#change-61828
* Author: Satoshi TAGOMORI
* Status: Open
* Priority: Normal
* Assignee:
----------------------------------------
When I parsed a binary protocol (msgpack) by `String#unpack`, there are many similar expressions, like below:
```ruby
str = io.read(1)
length = str.unpack('C').first
case length
when 4
data = io.read(4).unpack('N').first
# ...
```
I know that `unpack` returns "1 or more" values, but I think there are too many cases to return just one object.
Creating Array objects for return values requires additional cost to create Array object, and calling `.first`.
I'm happy if I can write the code above like this:
```ruby
str = io.read(1)
length = str.unpack('C', 0) # index, or str.unpack('C', index: 0)
case length
when 4
data = io.read(4).unpack('N', 0)
# ...
```
--
https://bugs.ruby-lang.org/
Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>