# YAML::quick\_emit api change

**URL:** <https://www.ruby-forum.com/t/yaml-quick-emit-api-change/100683>\
**Category:** Ruby\
**Created:** [February 3, 2006, 4:36pm UTC](https://www.ruby-forum.com/t/yaml-quick-emit-api-change/100683 "2006-02-03T16:36:50Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [February 3, 2006, 4:36pm UTC](https://www.ruby-forum.com/t/yaml-quick-emit-api-change/100683/1 "2006-02-03T16:36:50Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [February 3, 2006, 6:19pm UTC](https://www.ruby-forum.com/t/yaml-quick-emit-api-change/100683/2 "2006-02-03T18:19:21Z")

</div>

removed\_email\_address@domain.invalid wrote:

> 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’ =\> ‘removed\_email\_address@domain.invalid’, ‘x-mail-count’ =\> 178223,  
> > ‘from’ =\> ‘removed\_email\_address@domain.invalid’}
> 
> > def hsh.to\_yaml\_style; :inline end  
> > =\> nil
> 
> > y [hsh, {‘Subject’ =\> ‘Re: YAML::quick\_emit api change’}]

* * *

- {from: removed\_email\_address@domain.invalid, x-mail-count: 178223, to:  
removed\_email\_address@domain.invalid}
- 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

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [February 3, 2006, 6:31pm UTC](https://www.ruby-forum.com/t/yaml-quick-emit-api-change/100683/3 "2006-02-03T18:31:24Z")

</div>

On Sat, 4 Feb 2006, why the lucky stiff wrote:

> - {from: removed\_email\_address@domain.invalid, x-mail-count: 178223, to: removed\_email\_address@domain.invalid}
> - 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

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [February 3, 2006, 7:59pm UTC](https://www.ruby-forum.com/t/yaml-quick-emit-api-change/100683/4 "2006-02-03T19:59:05Z")

</div>

On Sat, 4 Feb 2006, why the lucky stiff wrote:

> If you really need to sniff, I’d use YAML::Syck::VERSION. In case you  
> “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

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [February 3, 2006, 6:46pm UTC](https://www.ruby-forum.com/t/yaml-quick-emit-api-change/100683/5 "2006-02-03T18:46:31Z")

</div>

removed\_email\_address@domain.invalid wrote:

> but is a nil value by default ok?

> > require ‘yaml’  
> > hsh = {‘to’ =\> ‘removed\_email\_address@domain.invalid’, ‘x-mail-count’ =\> 178223,  
> > ‘from’ =\> ‘removed\_email\_address@domain.invalid’}
> 
> > 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

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [February 3, 2006, 9:03pm UTC](https://www.ruby-forum.com/t/yaml-quick-emit-api-change/100683/6 "2006-02-03T21:03:40Z")

</div>

On Sat, 4 Feb 2006, why the lucky stiff wrote:

> removed\_email\_address@domain.invalid 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](http://code.whytheluckystiff.net/syck/changeset/212)

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

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [February 3, 2006, 8:48pm UTC](https://www.ruby-forum.com/t/yaml-quick-emit-api-change/100683/7 "2006-02-03T20:48:15Z")

</div>

removed\_email\_address@domain.invalid 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](http://code.whytheluckystiff.net/syck/changeset/212)

\_why
