[#23231] What do you think about changing the return value of Kernel#require and Kernel#load to the source encoding of the required file? — =?ISO-8859-15?Q?Wolfgang_N=E1dasi-Donner?= <ed.odanow@...>

Dear Ruby developers and users!

8 messages 2009/04/17

[#23318] [Feature #1408] 0.1.to_r not equal to (1/10) — Heesob Park <redmine@...>

Feature #1408: 0.1.to_r not equal to (1/10)

19 messages 2009/04/26

[ruby-core:23264] Re: [Feature #666](Rejected) Enumerable::to_hash

From: Joshua Ballanco <jballanc@...>
Date: 2009-04-20 15:22:09 UTC
List: ruby-core #23264
Hi Matz,

In the past, one of the suggestions for a #to_hash method has been to  
do something similar to #map. That is, to_hash would take a block and  
construct a hash using the elements of the Enumerable as the keys and  
the return value of the block as the values. This solves a slightly  
different problem then originally posed, but I think it would be a  
very useful function (even if it is little more than syntactic sugar  
for inject). In other words:

 > integers = [1, 2, 3, 4, 5, 6]
 > squares = integers.to_hash {|i| i**2}
 > p squares
{1=>1, 2=>4, 3=>9, 4=>16, 5=>25, 6=>36}

Which would be similar to:

 > integers = [1, 2, 3, 4, 5, 6]
 > squares = integers.inject({}) { |a, n| a[n] = n**2; a }

...but I feel the first way is much more straight forward. In addition  
to being prettier, I think a #to_hash like that would be open to more  
optimization than #inject. That is, #inject much pass the accumulator  
to each element in the Enumerable in turn, but #to_hash could  
preallocate the hash keys and evaluate the value blocks in parallel.

Just an idea

- Josh

On Apr 19, 2009, at 11:43 PM, Yukihiro Matsumoto wrote:

> Hi,
>
> In message "Re: [ruby-core:23253] Re: [Feature #666](Rejected)  
> Enumerable::to_hash"
>    on Sun, 19 Apr 2009 08:52:54 +0900, trans <transfire@gmail.com>  
> writes:
>
> |I don't see why a corresponance in needed. It's simply a
> |transformation.
>
> #to_hash (or whatever name of the method) can only transform
> enumerable in certain format, e.g. enumerable of two-elements arrays.
> I think this is too much assumption for a method of Enumerable.
>
> OK, I admit we already have some methods with presumption, e.g.
> #sort, #min and #max to assume elements to be comparable, but their
> usefulness is proven in the history of the language.  Meanwhile, how
> often do we need #to_hash?  I haven't, at least.
>
> |I think the real problem lies in the name of the
> |method proposed. Rather than #to_hash, for instance, in Facets this
> |method is called #graph or #mash (for "map hash"). Maybe there is a
> |better name to be had, but it certainly is a useful method to have at
> |times.
>
> Any method can be useful for certain situation.  The point is how
> often and in what situation it is useful.  I don't see that much
> usefulness to make it built in.
>
> 							matz.
>


In This Thread