From: Bob Norfolk Date: 2006-08-20T09:29:46+09:00 Subject: Re: {} as record separators? Scott wrote: > Wow, this can't be "The Ruby Way", but it works: > > def nagios_data(data) > blocks = data.strip.split(/.*\}\n(?=\w+\s+\{)/) > blocks.map do |nagios_data| > data_points = nagios_data.split("\n") > # you can possibly use this as a hash key if they will be unique > # block_name = data_points[0][/\w+/] > data_points[1..-1].inject({}) do |values, data_point| > unless data_point =~ /\s+\}/ > key, value = data_point.strip.sub(/#.*$/, "").split(/\s*=\s*/, 2) > values[key.intern] = value > end > values > end > end > end > > require 'pp' > > pp nagios_data(File.read("status.dat")) When I try running this code, I get: nagios_test2.rb:10:in `nagios_data': undefined method `intern' for nil:NilClass (NoMethodError) from nagios_test2.rb:7:in `inject' from nagios_test2.rb:7:in `each' from nagios_test2.rb:7:in `inject' from nagios_test2.rb:7:in `nagios_data' from nagios_test2.rb:3:in `map' from nagios_test2.rb:3:in `nagios_data' from nagios_test2.rb:19 Where does the intern method come from? -- Posted via http://www.ruby-forum.com/.