Hi Carmen

The documentation of class "Hash" contains the answer to your question

  http://www.ruby-doc.org/core/classes/Hash.html#M002868

By saying

h = Hash.new("Go Fish")

you build a Hash object that will use "Go Fish" as default value for every
key unless you set the value explicitly.

(...) If *obj* is specified, this single object will be used for all *
default <http://www.ruby-doc.org/core/classes/Hash.html#M002880>
values<http://www.ruby-doc.org/core/classes/Hash.html#M002895>
*. (...)

If you built the Hash object without providing any default value for every
key, every key will have its default value set to *nil* unless you set the
value explicitly.

aHash = Hash.new
puts aHash["a"] => nil

Sergio

On Sat, Apr 4, 2009 at 9: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