From: "tenderlovemaking (Aaron Patterson) via ruby-dev" Date: 2023-10-12T19:11:49+00:00 Subject: [ruby-dev:52053] [Ruby master Feature#18573] Object#pack1 Issue #18573 has been updated by tenderlovemaking (Aaron Patterson). matz (Yukihiro Matsumoto) wrote in #note-7: > Array.pack1 is unlikely because there is no connection between the responsibilities of the method and the Array class. I also disagree with String.pack1 for the same reason. > The most natural candidate is Object#pack1, but I question the need to pollute the namespace for this trivial method. > > Matz. Feature #18897 introduced a specialized instruction for Array#hash, but it created a new instruction called `opt_newarray_send`. I think we could leverage that instruction for the case of an array literal + pack. That would avoid the array creation. I will try to make a patch. ---------------------------------------- Feature #18573: Object#pack1 https://bugs.ruby-lang.org/issues/18573#change-104894 * Author: os (Shigeki OHARA) * Status: Open * Priority: Normal ---------------------------------------- # ������ String#unpack1 ��������� Object#pack1 ��������������� # ������ Array#pack ������������������������������������������������������������ Array ��������������� 1 ��������������������������������������������� ``` ruby [codepoint].pack('U') [digest].pack('m0') [mail_body].pack('M') [ip_address].pack('N') ``` ������������������������������������������������������������������������������������������ ��������������������������������������������������������������������������������������� Array ������������������������������������������������������������������������������ # ������ String#unpack ������������ String#unpack1 ������������������������������������������ Array#pack ������������ Object#pack1 ������������������������������������������ ��������������������������������������������������������������������� ``` ruby class Object def pack1(template, option = {}) [self].pack(template, **option) end end ``` # ��������������� * Object ��������������������������������������������������������������������� * ������������������ pack1 ������������������������������������������������������������������������������������������ -- https://bugs.ruby-lang.org/