From: "Ara.T.Howard" Date: 2004-08-21T00:45:56+09:00 Subject: Re: YAML and line numbers On Sat, 21 Aug 2004, Jamis Buck wrote: > Perhaps something like this: > > conf = YAML.load( File.read( "package.yml" ) ) > p conf['id'] #-> "my.package.id" > p conf['id'].line_number #-> 2 > > The above approach would give you the number of the first line on which > the requested value was defined. To find the line number on which the > key was defined, maybe something like this: > > conf.keys.each do { |key| p key.line_number } > > Because dynamically adding a line_number attribute to every object read > by the YAML parser would be prohibitively expensive for some > applications, you may even want to make it optional: > > YAML.line_numbers = true > conf = YAML.load(...) > ... > > Anyway, something like that would be sufficient for my needs. :) but how would that work with something like this: yaml = <<-yaml --- - array element 0 - array element 1 - array element 2 yaml array = YAML.load yaml p array.line_number # => 1 so each object returns would have the method 'line_number' added? guess that could work. perhaps something like obj.yaml_lineno though, since 'line_number' is a bit generic. cheers. -a -- =============================================================================== | EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov | PHONE :: 303.497.6469 | A flower falls, even though we love it; | and a weed grows, even though we do not love it. | --Dogen ===============================================================================