I want to iterate ?nodes? and ?leafs? for a yaml document:
thufir@ARRAKIS:~/projects/rss$
thufir@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
thufir@ARRAKIS:~/projects/rss$
thufir@ARRAKIS:~/projects/rss$ ruby user2.rb
user2.rb:5: undefined method `[]’ for nil:NilClass (NoMethodError)
thufir@ARRAKIS:~/projects/rss$
thufir@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 }
thufir@ARRAKIS:~/projects/rss$
thufir@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
thufir@ARRAKIS:~/projects/rss$
thufir@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
thufir@ARRAKIS:~/projects/rss$
thufir@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