https://redmine.ruby-lang.org/https://redmine.ruby-lang.org/favicon.ico?17113305112010-04-12T08:37:27ZRuby Issue Tracking SystemRuby master - Feature #3131: add Kernel#Hash() method like Kernel#Array()https://redmine.ruby-lang.org/issues/3131?journal_id=101132010-04-12T08:37:27Zsunaku (Suraj Kurapati)sunaku@gmail.com
<ul></ul><p>=begin<br>
I forgot to show that case 2 supports empty arrays:</p>
<blockquote>
<blockquote>
<p>Hash([])<br>
=> {}</p>
</blockquote>
</blockquote>
<p>Just like Kernel#Array() supports empty hashes:</p>
<blockquote>
<blockquote>
<p>Array({})<br>
=> []</p>
</blockquote>
</blockquote>
<p>Thanks for your consideration. And sorry for the noise.<br>
=end</p> Ruby master - Feature #3131: add Kernel#Hash() method like Kernel#Array()https://redmine.ruby-lang.org/issues/3131?journal_id=101432010-04-13T08:11:27Zmatz (Yukihiro Matsumoto)matz@ruby.or.jp
<ul></ul><p>=begin<br>
Hi,</p>
<p>In message "Re: <a href="/issues/3131">[ruby-core:29462]</a> [Feature <a class="issue tracker-2 status-5 priority-4 priority-default closed behind-schedule" title="Feature: add Kernel#Hash() method like Kernel#Array() (Closed)" href="https://redmine.ruby-lang.org/issues/3131">#3131</a>] add Kernel#Hash() method like Kernel#Array()"<br>
on Mon, 12 Apr 2010 08:32:52 +0900, Suraj Kurapati <a href="mailto:redmine@ruby-lang.org" class="email">redmine@ruby-lang.org</a> writes:</p>
<p>|There is an imbalance of power in the Ruby core API (when it comes<br>
|to arrays and hashes) because it is easier to convert nil values<br>
|into empty arrays, thanks to Kernel#Array(), than it is to convert<br>
|nil values into empty hashes, due to lack of Kernel#Hash().</p>
<p>Having Hash() might be a good idea. But since conversion from<br>
arrays only meaningful for specific case (array of 2-element arrays),<br>
I am not sure whether Hash() should support conversion from Array in<br>
general or not.</p>
<pre><code> matz.
</code></pre>
<p>=end</p> Ruby master - Feature #3131: add Kernel#Hash() method like Kernel#Array()https://redmine.ruby-lang.org/issues/3131?journal_id=101462010-04-13T09:03:47Zsunaku (Suraj Kurapati)sunaku@gmail.com
<ul></ul><p>=begin<br>
Hi,</p>
<p>matz wrote:</p>
<blockquote>
<p>since conversion from arrays only meaningful for specific case<br>
(array of 2-element arrays), I am not sure whether Hash() should<br>
support conversion from Array in general or not.</p>
</blockquote>
<p>Hash::[] does not support conversion from odd-length Array (because<br>
it is uncertain what Ruby must do with the 2n+1'th element) and will<br>
raise an error in such case. So, in my view, Kernel#Hash() need not<br>
support conversion from odd-length Array either.</p>
<p>If you wish to avoid even-length Array conversion in Kernel#Hash()<br>
because odd-length Array conversion is not supported, then I request<br>
that Kernel#Hash() must still support conversion from empty Array<br>
because Kernel#Array() already supports conversion from empty Hash:</p>
<blockquote>
<blockquote>
<p>Array({})<br>
=> []</p>
</blockquote>
</blockquote>
<p>In summary, I request that Kernel#Hash() supports conversion from:</p>
<ul>
<li>nil</li>
<li>Hash</li>
<li>empty Array</li>
</ul>
<p>It would be nice if Kernel#Hash() also supports conversion from:</p>
<ul>
<li>even-length Array</li>
</ul>
<p>Thanks for your consideration.<br>
=end</p> Ruby master - Feature #3131: add Kernel#Hash() method like Kernel#Array()https://redmine.ruby-lang.org/issues/3131?journal_id=101472010-04-13T09:19:11Zsunaku (Suraj Kurapati)sunaku@gmail.com
<ul></ul><p>=begin<br>
Hi,</p>
<p>Please allow me to clarify.</p>
<p>Suraj Kurapati wrote:</p>
<blockquote>
<p>Hash::[] does not support conversion from odd-length Array (because<br>
it is uncertain what Ruby must do with the 2n+1'th element) and will<br>
raise an error in such case.</p>
</blockquote>
<p>I was referring to this particular behavior:</p>
<blockquote>
<blockquote>
<p>Hash[1,2,3,4,5,6]<br>
=> {1=>2, 3=>4, 5=>6}</p>
</blockquote>
</blockquote>
<blockquote>
<blockquote>
<p>Hash[1,2,3,4,5,6,7]<br>
ArgumentError: odd number of arguments for Hash<br>
from (irb):3:in <code>[]' from (irb):3 from /usr/bin/irb:12:in </code>'</p>
</blockquote>
</blockquote>
<p>I forgot that Hash::[] can convert Array of 2-element Array into Hash:</p>
<blockquote>
<blockquote>
<p>Hash[1,2,3,4,[5,6],[7]] # non 2-element Array ignored<br>
=> {1=>2, 3=>4, [5, 6]=>[7]}</p>
</blockquote>
</blockquote>
<blockquote>
<blockquote>
<p>Hash[[1,2,3,4,[5,6],[7]]] # implicit pair value is nil<br>
=> {5=>6, 7=>nil}</p>
</blockquote>
</blockquote>
<blockquote>
<blockquote>
<p>Hash[[1,2,3,4,[5,6],[7,8],[7]]] # previous pair is overwritten<br>
=> {5=>6, 7=>nil}</p>
</blockquote>
</blockquote>
<p>Thanks for your consideration.<br>
=end</p> Ruby master - Feature #3131: add Kernel#Hash() method like Kernel#Array()https://redmine.ruby-lang.org/issues/3131?journal_id=103532010-04-20T13:35:59Zsunaku (Suraj Kurapati)sunaku@gmail.com
<ul></ul><p>=begin<br>
Hi Matz,</p>
<p>To avoid delaying this request forever due to unnecessary features,<br>
I have narrowed the requirements for Kernel#Hash() to the following:</p>
<p>Hash() must convert (1) nil, (2) Hash, and (3) empty Array into Hash.</p>
<pre><code> module Kernel
def Hash(value)
if value.respond_to? :to_hash
value.to_hash
elsif value.nil? or Array(value).empty?
{}
else
raise ArgumentError, "invalid value for Hash: #{value}"
end
end
end
</code></pre>
<p>Thanks for your consideration.<br>
=end</p> Ruby master - Feature #3131: add Kernel#Hash() method like Kernel#Array()https://redmine.ruby-lang.org/issues/3131?journal_id=104062010-04-21T22:23:27Zmatz (Yukihiro Matsumoto)matz@ruby.or.jp
<ul></ul><p>=begin<br>
Hi,</p>
<p>In message "Re: <a href="https://blade.ruby-lang.org/ruby-core/29644">[ruby-core:29644]</a> [Feature <a class="issue tracker-2 status-5 priority-4 priority-default closed behind-schedule" title="Feature: add Kernel#Hash() method like Kernel#Array() (Closed)" href="https://redmine.ruby-lang.org/issues/3131">#3131</a>] add Kernel#Hash() method like Kernel#Array()"<br>
on Tue, 20 Apr 2010 13:36:00 +0900, Suraj Kurapati <a href="mailto:redmine@ruby-lang.org" class="email">redmine@ruby-lang.org</a> writes:</p>
<p>|To avoid delaying this request forever due to unnecessary features,<br>
|I have narrowed the requirements for Kernel#Hash() to the following:<br>
|<br>
|Hash() must convert (1) nil, (2) Hash, and (3) empty Array into Hash.</p>
<p>Sounds reasonable. But the new feature window for 1.9.2 was closed.<br>
So, I will consider (positively) adding this feature after 1.9.2 release.</p>
<pre><code> matz.
</code></pre>
<p>=end</p> Ruby master - Feature #3131: add Kernel#Hash() method like Kernel#Array()https://redmine.ruby-lang.org/issues/3131?journal_id=104252010-04-22T06:53:23Zshyouhei (Shyouhei Urabe)shyouhei@ruby-lang.org
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Assigned</i></li><li><strong>Assignee</strong> set to <i>matz (Yukihiro Matsumoto)</i></li></ul><p>=begin</p>
<p>=end</p> Ruby master - Feature #3131: add Kernel#Hash() method like Kernel#Array()https://redmine.ruby-lang.org/issues/3131?journal_id=104682010-04-23T09:54:23Zsunaku (Suraj Kurapati)sunaku@gmail.com
<ul></ul><p>=begin<br>
Hi,</p>
<p>Matz wrote:</p>
<blockquote>
<p>I will consider (positively) adding this feature after 1.9.2<br>
release.</p>
</blockquote>
<p>Thanks Matz! In the mean time, I have created a gem with this<br>
functionality so that people can start using it, if they wish:</p>
<p><a href="http://rubygems.org/gems/kernel_hash" class="external">http://rubygems.org/gems/kernel_hash</a></p>
<p>The source code (and unit tests) is available here:</p>
<p><a href="http://github.com/sunaku/kernel_hash" class="external">http://github.com/sunaku/kernel_hash</a></p>
<p>Cheers.<br>
=end</p> Ruby master - Feature #3131: add Kernel#Hash() method like Kernel#Array()https://redmine.ruby-lang.org/issues/3131?journal_id=112272010-05-25T15:57:34Zsunaku (Suraj Kurapati)sunaku@gmail.com
<ul></ul><p>=begin<br>
Hi,</p>
<p>Please set the "Done %" for this issue to 80%.</p>
<p>The remaining 20% is for (possibly) rewriting<br>
my proposed Kernel#Hash() Ruby code in C.</p>
<p>Thanks for your consideration.<br>
=end</p> Ruby master - Feature #3131: add Kernel#Hash() method like Kernel#Array()https://redmine.ruby-lang.org/issues/3131?journal_id=131322010-09-02T23:03:07Zrunpaint (Run Paint Run Run)runrun@runpaint.org
<ul><li><strong>File</strong> <a href="/attachments/1175">kernel-hash.patch</a> <a class="icon-only icon-download" title="Download" href="/attachments/download/1175/kernel-hash.patch">kernel-hash.patch</a> added</li></ul><p>=begin<br>
I believe the attached patch reflects the consensus between matz and Suraj. The only material difference is that a TypeError is raised instead of an ArgumentError for consistency with Integer(), Float(), etc.<br>
=end</p> Ruby master - Feature #3131: add Kernel#Hash() method like Kernel#Array()https://redmine.ruby-lang.org/issues/3131?journal_id=165922011-04-23T08:52:04Zsunaku (Suraj Kurapati)sunaku@gmail.com
<ul></ul><p>=begin<br>
Integer() and Float() in Ruby 1.9.2 raise TypeError and ArgumentError:</p>
<p>$ irb</p>
<a name="ruby-192p180-2011-02-18-revision-30909-x86_64-linux"></a>
<h2 >ruby 1.9.2p180 (2011-02-18 revision 30909) [x86_64-linux]<a href="#ruby-192p180-2011-02-18-revision-30909-x86_64-linux" class="wiki-anchor">¶</a></h2>
<blockquote>
<blockquote>
<p>Float(nil)<br>
TypeError: can't convert nil into Float<br>
from (irb):6:in <code>Float' from (irb):6 from /usr/bin/irb:12:in </code>'<br>
Float('meow')<br>
ArgumentError: invalid value for Float(): "meow"<br>
from (irb):8:in <code>Float' from (irb):8 from /usr/bin/irb:12:in </code>'</p>
</blockquote>
</blockquote>
<p>I don't know which error type we should raise in Kernel#Hash().<br>
=end</p> Ruby master - Feature #3131: add Kernel#Hash() method like Kernel#Array()https://redmine.ruby-lang.org/issues/3131?journal_id=165952011-04-23T22:23:06Zmatz (Yukihiro Matsumoto)matz@ruby.or.jp
<ul></ul><p>=begin<br>
Hi,</p>
<p>In message "Re: <a href="https://blade.ruby-lang.org/ruby-core/35857">[ruby-core:35857]</a> [Ruby 1.9 - Feature <a class="issue tracker-2 status-5 priority-4 priority-default closed behind-schedule" title="Feature: add Kernel#Hash() method like Kernel#Array() (Closed)" href="https://redmine.ruby-lang.org/issues/3131">#3131</a>] add Kernel#Hash() method like Kernel#Array()"<br>
on Sat, 23 Apr 2011 08:52:12 +0900, Suraj Kurapati <a href="mailto:sunaku@gmail.com" class="email">sunaku@gmail.com</a> writes:</p>
<p>|Integer() and Float() in Ruby 1.9.2 raise TypeError and ArgumentError:</p>
<p>I think they should raise TypeError, if incompatibly here is not an<br>
issue, I will fix.</p>
<pre><code> matz.
</code></pre>
<p>=end</p> Ruby master - Feature #3131: add Kernel#Hash() method like Kernel#Array()https://redmine.ruby-lang.org/issues/3131?journal_id=209852011-09-26T05:22:58Zsunaku (Suraj Kurapati)sunaku@gmail.com
<ul></ul><p>Any chance of this getting into Ruby 1.9.3? Thanks.</p> Ruby master - Feature #3131: add Kernel#Hash() method like Kernel#Array()https://redmine.ruby-lang.org/issues/3131?journal_id=209882011-09-26T06:59:08Zyeban (Anurag Priyam)anurag08priyam@gmail.com
<ul></ul><p>On Mon, Sep 26, 2011 at 1:52 AM, Suraj Kurapati <a href="mailto:sunaku@gmail.com" class="email">sunaku@gmail.com</a> wrote:</p>
<blockquote>
<p>Issue <a class="issue tracker-2 status-5 priority-4 priority-default closed behind-schedule" title="Feature: add Kernel#Hash() method like Kernel#Array() (Closed)" href="https://redmine.ruby-lang.org/issues/3131">#3131</a> has been updated by Suraj Kurapati.</p>
<p>Any chance of this getting into Ruby 1.9.3? Â Thanks.</p>
</blockquote>
<p>Doesn't look like it. See ruby-core 39693.</p>
<p>--<br>
Anurag Priyam</p> Ruby master - Feature #3131: add Kernel#Hash() method like Kernel#Array()https://redmine.ruby-lang.org/issues/3131?journal_id=210192011-09-27T08:17:21Zsunaku (Suraj Kurapati)sunaku@gmail.com
<ul></ul><p>Thanks for the pointer. I'll just wait for Ruby 1.9.4 then.</p> Ruby master - Feature #3131: add Kernel#Hash() method like Kernel#Array()https://redmine.ruby-lang.org/issues/3131?journal_id=234182012-01-24T12:36:59Zmatz (Yukihiro Matsumoto)matz@ruby.or.jp
<ul></ul><p>I accept this patch for trunk, except that Hash(nil) should return an empty hash, not nil.</p>
<p>Matz.</p> Ruby master - Feature #3131: add Kernel#Hash() method like Kernel#Array()https://redmine.ruby-lang.org/issues/3131?journal_id=241252012-02-25T14:46:38Zko1 (Koichi Sasada)
<ul></ul><p>Who should work on it?</p> Ruby master - Feature #3131: add Kernel#Hash() method like Kernel#Array()https://redmine.ruby-lang.org/issues/3131?journal_id=241292012-02-25T15:13:17Znaruse (Yui NARUSE)naruse@airemix.jp
<ul><li><strong>Status</strong> changed from <i>Assigned</i> to <i>Closed</i></li></ul><p>This has already done, only missed to close.</p>