i had a method like this in my OrderedHash class
def yaml_inline= bool
unless defined? @__yaml_inline_meth
@__yaml_inline_meth =
lambda {|opts|
YAML::quick_emit(id, opts) {|emitter|
emitter << '{ ' << map{|kv| kv.join ': '}.join(', ') << ' }'
}
}
class << self
def to_yaml opts = {}
@__yaml_inline ? @__yaml_inline_meth[ opts ] : super
end
end
end
@__yaml_inline = bool
end
which toggled the yaml output style from the standard one to an inline one. it
blows up now (1.8.4) with
NoMethodError: undefined method `<<' for nil:NilClass
and indeed
jib:~ > ruby -r yaml -e ' YAML::quick_emit(object_id){|e| p [RUBY_VERSION, e.class]; exit} '
["1.8.1", YAML::Syck::Emitter]
harp:~ > ruby -r yaml -e ' YAML::quick_emit(object_id){|e| p [RUBY_VERSION, e.class]; exit} '
["1.8.4", YAML::Syck::Out]
i checked in the docs and am reading the source now - but the fix isn't jumping
out at me. any ideas?
ps. what's with the tab madness in the yaml src! ick.
cheers.
-a
···
--
happiness is not something ready-made. it comes from your own actions.
- h.h. the 14th dali lama
which toggled the yaml output style from the standard one to an inline one. it
blows up now (1.8.4) with
NoMethodError: undefined method `<<' for nil:NilClass
Yeah, you can't write directly to the output stream any longer. But the emitter is much smarter, more capable now (and utterly non-rdoc'd).
In current versions, you can define a `to_yaml_style' method which expects a symbol describing how to output the object. In this case, you'll want to reply with :inline.
>> hsh = {'to' => 'ara.t.howard@noaa.gov', 'x-mail-count' => 178223, 'from' => 'why@ruby-lang.org'}
>> def hsh.to_yaml_style; :inline end
=> nil
···
ara.t.howard@noaa.gov wrote:
>> y [hsh, {'Subject' => 'Re: YAML::quick_emit api change'}]
---
- {from: why@ruby-lang.org, x-mail-count: 178223, to: ara.t.howard@noaa.gov}
- Subject: "Re: YAML::quick_emit api change"
=> nil
i checked in the docs and am reading the source now - but the fix isn't jumping
out at me. any ideas?
I just need to improve the rdoc. What a sorry state I've left us all in!
_why
which toggled the yaml output style from the standard one to an inline one. it
blows up now (1.8.4) with
NoMethodError: undefined method `<<' for nil:NilClass
Yeah, you can't write directly to the output stream any longer. But the emitter is much smarter, more capable now (and utterly non-rdoc'd).
In current versions, you can define a `to_yaml_style' method which expects a symbol describing how to output the object. In this case, you'll want to reply with :inline.
>> hsh = {'to' => 'ara.t.howard@noaa.gov', 'x-mail-count' => 178223, 'from' => 'why@ruby-lang.org'}
>> def hsh.to_yaml_style; :inline end
=> nil
>> y [hsh, {'Subject' => 'Re: YAML::quick_emit api change'}]
---
- {from: why@ruby-lang.org, x-mail-count: 178223, to: ara.t.howard@noaa.gov}
- Subject: "Re: YAML::quick_emit api change"
=> nil
since i need to toggle i'll probably do
class OrderedHash
attr_accessor "to_yaml_style"
end
oh.to_yaml_style = :inline
but is a nil value by default ok? or do i need
class OrderedHash
attr_accessor "to_yaml_style"
def to_yaml_style
@to_yaml_style ||= :some_default
end
end
??
any thoughts on how to conditionally define this stuff by RUBY_VERSION? my
old method worked with 1.8.1 and 1.8.2 - maybe
if RUBY_VERSION >= "1.8.4"
new_way
else
old_way
end
??
i checked in the docs and am reading the source now - but the fix isn't jumping
out at me. any ideas?
I just need to improve the rdoc. What a sorry state I've left us all in!
heh. you won't here me complaining! the people that complain about lack of
docs are people who don't write libraries or who don't write that many - it's
hard enough writing code. let them eat cake.
-a
···
On Sat, 4 Feb 2006, why the lucky stiff wrote:
ara.t.howard@noaa.gov wrote:
--
happiness is not something ready-made. it comes from your own actions.
- h.h. the 14th dali lama
but is a nil value by default ok?
>> require 'yaml'
>> hsh = {'to' => 'ara.t.howard@noaa.gov', 'x-mail-count' => 178223, 'from' => 'why@ruby-lang.org'}
>> hsh.to_yaml_style
=> nil
If you really need to sniff, I'd use YAML::Syck::VERSION. In case you encounter someone who'se upgraded their extension.
why@stungun ~ $ ~/sand/RUBY-1_8_4/bin/ruby -v -ryaml -e 'p YAML::Syck::VERSION'
ruby 1.8.4 (2005-12-24) [i686-linux]
"0.60"
why@stungun ~ $ ~/sand/RUBY-1_8_3/bin/ruby -v -ryaml -e 'p YAML::Syck::VERSION'
ruby 1.8.3 (2005-09-21) [i686-linux]
"0.60"
why@stungun ~ $ ~/sand/RUBY-1_8_2/bin/ruby -v -ryaml -e 'p YAML::Syck::VERSION'
ruby 1.8.2 (2004-12-25) [i686-linux]
"0.45"
There shouldn't be any 0.5x Sycks floating around in stable Ruby releases.
_why
···
ara.t.howard@noaa.gov wrote:
and where would the to_yaml_style attr come in at - which version is the break
point?
-a
···
On Sat, 4 Feb 2006, why the lucky stiff wrote:
ara.t.howard@noaa.gov wrote:
but is a nil value by default ok?
>> require 'yaml'
>> hsh = {'to' => 'ara.t.howard@noaa.gov', 'x-mail-count' => 178223, 'from' => 'why@ruby-lang.org'}
>> hsh.to_yaml_style
=> nil
If you really need to sniff, I'd use YAML::Syck::VERSION. In case you encounter someone who'se upgraded their extension.
why@stungun ~ $ ~/sand/RUBY-1_8_4/bin/ruby -v -ryaml -e 'p YAML::Syck::VERSION'
ruby 1.8.4 (2005-12-24) [i686-linux]
"0.60"
why@stungun ~ $ ~/sand/RUBY-1_8_3/bin/ruby -v -ryaml -e 'p YAML::Syck::VERSION'
ruby 1.8.3 (2005-09-21) [i686-linux]
"0.60"
why@stungun ~ $ ~/sand/RUBY-1_8_2/bin/ruby -v -ryaml -e 'p YAML::Syck::VERSION'
ruby 1.8.2 (2004-12-25) [i686-linux]
"0.45"
There shouldn't be any 0.5x Sycks floating around in stable Ruby releases.
--
happiness is not something ready-made. it comes from your own actions.
- h.h. the 14th dali lama
0.55:
http://code.whytheluckystiff.net/syck/changeset/212
_why
···
ara.t.howard@noaa.gov wrote:
and where would the to_yaml_style attr come in at - which version is the break
point?
sweet. thanks. running on all my ruby version now - this was for rq btw, so
i really wanted it to work for as many versions as possible. i use yaml
heavily for that project.
cheers.
-a
···
On Sat, 4 Feb 2006, why the lucky stiff wrote:
ara.t.howard@noaa.gov wrote:
and where would the to_yaml_style attr come in at - which version is the break
point?
0.55:
http://code.whytheluckystiff.net/syck/changeset/212
--
happiness is not something ready-made. it comes from your own actions.
- h.h. the 14th dali lama