I want to iterate ?nodes? and ?leafs? for a yaml document:

thu...@arrakis:~/projects/rss$ 
thu...@arrakis:~/projects/rss$ ruby user.rb
user.rb:6: undefined method `[]' for nil:NilClass (NoMethodError)
        from user.rb:5:in `each_key'
        from user.rb:5
thu...@arrakis:~/projects/rss$ 
thu...@arrakis:~/projects/rss$ ruby user2.rb 
user2.rb:5: undefined method `[]' for nil:NilClass (NoMethodError)
thu...@arrakis:~/projects/rss$ 
thu...@arrakis:~/projects/rss$ nl user.rb 
     1  require 'yaml'
       
     2  yml = YAML::load(File.open('user.yml'))
       
     3  yml.each_key { |key|
     4    username = yml[key]['user']
     5    password = yml[key]['pass']
       
     6    puts "#{username} => #{password}"
     7  }
thu...@arrakis:~/projects/rss$ 
thu...@arrakis:~/projects/rss$ nl user2.rb 
     1  require 'yaml'
       
     2  yml = YAML::load(File.open('user.yml'))
       
     3  username = yml['juixe']['user']
       
     4  puts username
thu...@arrakis:~/projects/rss$ 
thu...@arrakis:~/projects/rss$ nl user.yml 
     1  juixe:
     2  user: juixe-user
     3  pass: juixe-pass
       
     4  techknow:
     5  user: techknow-user
     6  pass: techknow-pass
thu...@arrakis:~/projects/rss$ 
thu...@arrakis:~/projects/rss$ 




http://yaml.kwiki.org/index.cgi?YamlInFiveMinutesMinuteThree refers to 
this structure as a nested map, FWIW.  In either event, how would you 
either iterate through the entire structure, or specify the "juixe" map 
(or node)?


thanks,

Thufir


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to