From: Prasadhnc C Date: 2013-01-30T15:03:50+09:00 Subject: Re: newbie question.. --0023544718fc781e8904d47ae95c Content-Type: text/plain; charset=ISO-8859-1 u can try this, string = 'hello' string.split('').each.inject(Hash.new(0)) { |h, char| h[char] += 1; h } Prasad C On Wed, Jan 30, 2013 at 9:38 AM, Ryan Victory wrote: > Out of curiosity, what did you do to get it working? I played around in > irb after sending that (it was a quick guess, not anything I tried > first) and ended up using two lines, both with > Enumerable#each...couldn't get the hash to be used as the accumulator. > > -Ryan Victory > > On 1/29/13 8:55 PM, tamouse mailing lists wrote: > > On Tue, Jan 29, 2013 at 8:45 PM, tamouse mailing lists > > wrote: > >> On Tue, Jan 29, 2013 at 2:52 PM, Ryan Victory > wrote: > >>> For the same reason, I won't give you any answers, but your problem > >>> could probably be solved using about two lines with the Array.inject > >>> method and a Hash...think about it and ask questions. We are all here > to > >>> help, but we wouldn't want it to be too easy for you :-) > >> > >> Ok, I admit I'm stumped -- I don't get how to use a Hash inside an > >> Array.inject -- I'm thinking it must be able to be done that way, but > >> I just cannot grok it. > >> > >> #inject/#reduce/#fold are accumulators, but how does the Hash get > >> passed from round to round? > > Never mind, I got it... > > > > > --0023544718fc781e8904d47ae95c Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
u can try this,
=A0
string =3D 'hello= 9;
string.split('').each.inject(Hash.new(0)) { |h, char| = h[char] +=3D 1; h }
=A0
Prasad C
On Wed, Jan 30, 2013 at 9:38 AM, Ryan Victory <ryan@raptormail.net&g= t; wrote:
Out of curiosity, what did you do to get it working? I played around in
irb after sending that (it was a quick guess, not anything I tried
first) and ended up using two lines, both with
Enumerable#each...couldn't get the hash to be used as the accumulator.<= br>
-Ryan Victory

On 1/29/13 8:55 PM, tamouse mailing lists wrote:
> On Tue, Jan 29, 2013 at 8:45 PM, tamouse mailing lists
> <tamouse.lists@gmail.com= > wrote:
>> On Tue, Jan 29, 2013 at 2:52 PM, Ryan Victory <ryan@raptormail.net> wrote:
>>> For the same reason, I won't give you any answers, but you= r problem
>>> could probably be solved using about two lines with the Array.= inject
>>> method and a Hash...think about it and ask questions. We are a= ll here to
>>> help, but we wouldn't want it to be too easy for you :-) >>
>> Ok, I admit I'm stumped -- I don't get how to use a Hash i= nside an
>> Array.inject -- I'm thinking it must be able to be done that w= ay, but
>> I just cannot grok it.
>>
>> #inject/#reduce/#fold are accumulators, but how does the Hash get<= br> >> passed from round to round?
> Never mind, I got it...
>



--0023544718fc781e8904d47ae95c--