jimweirich / builder

Provide a simple way to create XML markup and data structures.
http://builder.rubyforge.org
MIT License
362 stars 105 forks source link

(Sometimes) breaks blankslate on ruby 1.9 #19

Closed ronen closed 12 years ago

ronen commented 12 years ago

Hi,

Using ruby 1.9, if builder is required before blankslate, blankslate no longer works:

# WORKS: require blankslate without builder, as expected  BlankSlate#methods is undefined
$ ruby-1.9.3-p0 -rblankslate -e 'puts BlankSlate.new.methods'
-e:1:in `<main>': undefined method `methods' for #<BlankSlate:0x007ffaa1931158> (NoMethodError)

# WORKS: require blankslate then builder, as expected BlankSlate#methods is undefined
$ ruby-1.9.3-p0 -rblankslate -rbuilder -e 'puts BlankSlate.new.methods'
-e:1:in `<main>': undefined method `methods' for #<BlankSlate:0x007ffaa1931158> (NoMethodError)

# DOESN'T WORK: require builder then blankslate, BlankSlate is no longer blank!
$ ruby-1.9.3-p0 -rblankslate -rbuilder -e 'puts BlankSlate.new.methods'
[... lists all 56 methods of Object...]

Turns out that builder puts a file "blankslate.rb" into the load path, so it gets loaded instead of the blankslate gem. But this version doesn't work with ruby 1.9 (Object#methods returning symbols vs strings).

This isn't a problem for builder on its own, since it doesn't require blankslate.rb with ruby 1.9. And you might argue that one should use BasiicObject rather than BlankSlate. But I have an app that's using two other gems, one of which requires builder and the other requires blankslate. Depending on what order bundler ends up sorting out the dependencies, the app breaks.

I was going to do a patch and pull request, but i see four possible solutions, not sure which you'd prefer:

Thanks

johnlcox commented 12 years ago

I'm seeing this issue in a project using jbuilder. It would be nice to have a fix so I don't have to put a workaround in my project.

jimweirich commented 12 years ago

I've re-enabled the blank slate tests under ruby 1.9 and made sure it works in that version.