On Wed, Jan 6, 2010 at 1:52 PM, David Masover <ninja / slaphack.com> wrote:
> On Tuesday 05 January 2010 09:39:53 pm Ruby Newbee wrote:
>> Since I have created a key/value pair with hash['abc'] << 3, why
>> hash.keys show nothing?
>
> Because you haven't set anything in the hash. That is,
>
> hash['abc'] = 3
>
> is equivalent to:
>
> hash.[]=('abc', 3)
>
> On the other hand, what you've done is:
>
> hash['abc'] << 3
>
> That's equivalent to:
>
> hash.[]('abc') << 3
>


Thanks for the explaining, now I think I have got it.
I'm always thinking it as the Perl way, since in Perl the syntax like
hash['abc'] << 3 will create a key/value pairs.

perl -MData::Dumper -le '$hash={}; push @{$hash->{'abc'}},3; print Dumper $hash'
$VAR1 = {
          'abc' => [
                     3
                   ]
        };


I didn't know in Ruby hash['abc'] = 3 and hash['abc'] << 3 are different.
Thanks again.