>>>>> "s" == sarayu balu <sbalu / nyx.net> writes:

s> h = Hash.new
s> h['1']['2'] = '10' gives error undefined methos '[]=' for nil

 ruby don't create automatically new entries for a hash
(i.e.auto-vivification). This mean that in your example h['1'] give nil (it
was never assigned), then ruby try

   nil['2'] = '10'

 and this give an error.

 If you want that ruby automatically create new entries see the message
 [ruby-talk:13402]

  http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/13402

s> h['1'] = '10' is OK
s> h['1']['2'] = '10' is OK too
s> print h gives 110nil - this I don't understand

 First you assign the string '10' to h['1'], then you index this string
 with '2' and replace the content (if it found) with '10'

 For example :

 s = "string"
 s["tri"]         # tri
 s["tro"]         # nil (tro was not found in the string)

 s["tro"] = "XX"  # unchanged  (tro was not found in the string)
 s["tri"] = "XX"  #  sXXng (tri was replaced with XX)

 In you case '2' was not found in '10' and ruby has not modified the hash,
 i.e. a little example

pigeon% ruby
h = {}
h['1'] = 'abcd'
h['1']['2'] = 'XX'
p h
h['1']['c'] = 'XX'
p h
^D
{"1"=>"abcd"}
{"1"=>"abXXd"}
pigeon% 


Guy Decoux