"Go Fish" would be the default value returned if a key does not exist. You
can see this if you type the your code into irb. If you experiment around a
bit you will find the puts h[:anything_but_a] will return "Go Fish". Even
'puts h["Go Fish"]' returns "Go Fish". But to really see what the has
contains, at a prompt in irb (after putting in your example code), just type
'h' and hit enter. Irb will output a text representation of your object that
should look like this:

irb(main):008:0> h
=> {"a"=>100}

As you can see it is not a "complete" representation, as "Go Fish" is no
where to be seen, but the experimenting above shows it must be the default
value for keys that do not exist and the only key/value pair assigned is a
=> 100.

Irb is really great at helping you examine and play with your objects. You
can really get an understanding because you can easily manipulate them to
see how they work. Hope that helped.

On Sat, Apr 4, 2009 at 3:36 AM, Carmen <[email protected]> wrote:

>
> Can somebody please explain the following:
>
> h = Hash.new("Go Fish")
> h[:a] = 100
>
> puts h[:a]           #=> 100
> puts h[:c]           #=> "Go Fish"
>
> is the default string "Go Fish" a key to h or a value?
>
> Thank you.
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "ruby-on-rails-programming-with-passion" group.
To unsubscribe from this group, send email to
ruby-on-rails-programming-with-passion-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/ruby-on-rails-programming-with-passion?hl=en?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to