[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: Hash#rekey

Yukihiro Matsumoto

2/4/2007 6:38:00 PM

Hi,

In message "Re: Hash#rekey"
on Mon, 5 Feb 2007 03:08:15 +0900, "Trans" <transfire@gmail.com> writes:

|> No. "foo" and :foo are different keys in a hash.
|
|And never the twain shall meet? So it's long live
|HashWithIndifferentAccess ?

The HashWithIndifferentAccess behavior will not be default even after
Ruby 2.0; that's for sure.

|A while back I offered the idea of being able to define a key coerce
|proc, eg.
|
| h = Hash.new.key!{ |k| k.to_s }
|
|Such that keys would always be strings. Might someting like that be a
|viable solution?

Maybe, but not with a name like "key!".

|In anycase, I still offer up #rekey.

I don't think "rekey" represents the behavior well. Any better name?
transpose_keys comes to my mind.

matz.

3 Answers

Devin Mullins

2/4/2007 8:39:00 PM

0

Yukihiro Matsumoto wrote:
> In message "Re: Hash#rekey"
> on Mon, 5 Feb 2007 03:08:15 +0900, "Trans" <transfire@gmail.com> writes:
> |A while back I offered the idea of being able to define a key coerce
> |proc, eg.
> |
> | h = Hash.new.key!{ |k| k.to_s }
> |
> |Such that keys would always be strings. Might someting like that be a
> |viable solution?
I quite like this idea.

> Maybe, but not with a name like "key!".
key_coerce? coerce_key? key_proc=?

> I don't think "rekey" represents the behavior well. Any better name?
> transpose_keys comes to my mind.
Well, given what it's doing, map_key! seems logical -- map! + each_key.
('course, logical != intuitive...)

Devin

Trans

2/4/2007 10:35:00 PM

0



On Feb 4, 1:37 pm, Yukihiro Matsumoto <m...@ruby-lang.org> wrote:
> Hi,
>
> In message "Re: Hash#rekey"
> on Mon, 5 Feb 2007 03:08:15 +0900, "Trans" <transf...@gmail.com> writes:
>
> |> No. "foo" and :foo are different keys in a hash.
> |
> |And never the twain shall meet? So it's long live
> |HashWithIndifferentAccess ?
>
> The HashWithIndifferentAccess behavior will not be default even after
> Ruby 2.0; that's for sure.

Okay, well I though the whole reason you considerd making Symbols a
subclass of String was basically to remove the need for this sort of
thing. Honestly, keyword lists are increasing common as prameter args
and I for get tired of putting

opts = opts.stringify_keys

at the beginning of every such method. not to mention normalizing keys
when the are stored in such hash.

> |A while back I offered the idea of being able to define a key coerce
> |proc, eg.
> |
> | h = Hash.new.key!{ |k| k.to_s }
> |
> |Such that keys would always be strings. Might someting like that be a
> |viable solution?
>
> Maybe, but not with a name like "key!".
>
> |In anycase, I still offer up #rekey.
>
> I don't think "rekey" represents the behavior well. Any better name?
> transpose_keys comes to my mind.

I used 'normalize_keys' for while, but how doesn't 'rekey' fit the
behavior? The hash is being rekey'd.

T.


Steve

11/21/2010 11:04:00 PM

0

On Sun, 21 Nov 2010 13:04:40 -0600, "5813 Dead, 956 since 1/20/09"
<deadis@deadduz.com> wrote:

>On Sun, 21 Nov 2010 07:38:26 +0000, Ray Fischer wrote:
>
>> Harold Burton <hal.i.burton@hotmail.com> wrote:
>>>In article <j6WdnWqZnIBaeX_RnZ2dnUVZ_gOdnZ2d@posted.carinet>,
>>> "5791 Dead, 934 since 1/20/09" <deadis@deadduz.com> wrote:
>>>
>>>> On Tue, 16 Nov 2010 11:43:01 -0800, jane wrote:
>>>>
>>>> > On Nov 16, 2:32?pm, "5791 Dead, 934 since 1/20/09"
>>>> > <dea...@deadduz.com> wrote:
>>>> >> On Tue, 16 Nov 2010 08:42:28 -0800, jane wrote:
>>>> >> > On Nov 16, 10:48?am, Phlip <phlip2...@gmail.com> wrote:
>>>> >> >> On Nov 16, 7:42?am, jane <jane.pla...@gmail.com> wrote:
>>>> >>
>>>> >> >> > On Nov 15, 9:54?pm, "5791 Dead, 934 since 1/20/09"
>>>> >>
>>>> >> >> > <dea...@deadduz.com> wrote:
>>>> >> >> > > On Mon, 15 Nov 2010 21:02:48 -0500, Harold Burton wrote:
>>>> >> >> > > > In article
>>>> >> >> > > > <ba-dnQRAw8R-KX3RnZ2dnUVZ_qadn...@posted.carinet>,
>>>> >> >> > > > ?"5791 Dead, 934 since 1/20/09" <dea...@deadduz.com>
>>>> >> >> > > > ?wrote:
>>>> >>
>>>> >> >> > > >> Incidentally, the administrative overhead of SS is less
>>>> >> >> > > >> than 1%.
>>>> >>
>>>> >> >> > > > Yeah, and? ?I too could set up a Ponzi scheme with an
>>>> >> >> > > > administrative overhead of less than 1%.
>>>> >>
>>>> >> >> > > > snicker.
>>>> >>
>>>> >> >> > > Most ponzi schemes don't have a nest egg of $2 trillion.
>>>> >>
>>>> >> >> > > Don't you ever get tired of telling really stupid lies?
>>>> >>
>>>> >> >> > I don't call Social Security a ponzi scheme, BUT there are
>>>> >> >> > many similarities. ?Let me point out two of these
>>>> >> >> > similarities.
>>>> >>
>>>> >> >> > 1: ?There isn't a nest egg containing $2 Trillion. ?Like ponzi
>>>> >> >> > schemes, that $2 Trillion is GONE; congress spent that money.
>>>> >>
>>>> >> >> > 2: ?Like ponzi schemes, ?the "nest egg" contains promises to
>>>> >> >> > pay the current participants with revenue from future
>>>> >> >> > participants.
>>>> >>
>>>> >> >> Don't Ponzi schemes return nothing of value, such that no money
>>>> >> >> entering the system matches any value exiting the system?
>>>> >>
>>>> >> >> (Also, don't they _conceal_ their Ponzi status?)
>>>> >>
>>>> >> > Not necessarily; for example, in the Madoff scheme the
>>>> >> > participants will get pennies on the dollar.
>>>> >>
>>>> >> > In the case of the Social Security, the Trustees stated that
>>>> >> > there will be only enough revenue to pay 75 cents on every dollar
>>>> >> > of scheduled benefits.
>>>> >>
>>>> >> AFTER 2037, and then only if the economy remains at its present low
>>>> >> level.
>>>> >>
>>>> >>
>>>> >>
>>>> >> > As I stated in my first sentence, I, personally, do not use the
>>>> >> > term PONZI SCHEME. ?However, there are certain aspects that have
>>>> >> > similarities.
>>>> >
>>>> > You make it sound like 2037 is so far away. It is the retirement
>>>> > date of someone who is 40 years old TODAY.
>>>>
>>>> It's still 27 years down the road
>>>
>>>And you sound stupid enough to be someone who is young enough to
>>>stupidly believe that there will be money to pay you.
>>
>> You're obviously a rightard liar. The SSA has stated they will continue
>> paying benefits indefinitely even without any changes.
>
>And SS, the most wildly popular and successful government program in
>history, needs only minor adjustments now to get over the population bump
>25 years from now. Raising the cut-off level by 10% would more than do
>it.

Typical leftist loser... Jamieson always want's more of other
people's money.

--

The leftists' concept of "freedom" involves living
forever as a child in the loving arms of benevolent,
caring mother government who will supply them with
all the needs she thinks they should have and will also
insure that everything they say and do will comply
exactly with her plan for them.