YAML::quick_emit api change

A

ara.t.howard

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
 
W

why the lucky stiff

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' => '(e-mail address removed)', 'x-mail-count' => 178223, 'from' => '(e-mail address removed)'}
def hsh.to_yaml_style; :inline end => nil
y [hsh, {'Subject' => 'Re: YAML::quick_emit api change'}]
---
- {from: (e-mail address removed), x-mail-count: 178223, to:
(e-mail address removed)}
- 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
 
A

ara.t.howard

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' => '(e-mail address removed)', 'x-mail-count' => 178223, 'from' => '(e-mail address removed)'}
def hsh.to_yaml_style; :inline end => nil
y [hsh, {'Subject' => 'Re: YAML::quick_emit api change'}]

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 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
 
W

why the lucky stiff

but is a nil value by default ok?
=> 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
 
A

ara.t.howard

but is a nil value by default ok?
=> 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.

and where would the to_yaml_style attr come in at - which version is the break
point?

-a
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,772
Messages
2,569,593
Members
45,108
Latest member
AlbertEste
Top