From: Jamis Buck Date: 2004-08-21T00:12:32+09:00 Subject: Re: YAML and line numbers why the lucky stiff wrote: > Jamis Buck wrote: > >> Is it possible (or would it be difficult to add a way) to discover the >> line number on which a value in a YAML document was defined? > > > Not in the Ruby extension. This data is available in Syck, so it's > possible. Hmm-m-m. Do you have any suggestions for how you want to > retrieve this? Psuedo-code? > > _why > > . > 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. :) -- Jamis Buck jgb3@email.byu.edu http://www.jamisbuck.org/jamis "I use octal until I get to 8, and then I switch to decimal."