Is this a YAML bug?

J

Jim

The code:

require "http-access2"
require "yaml"

client = HTTPClient.new

File.open("client.yml", "w") do |file|
file.puts client.to_yaml
end

client2 = YAML.load( File.read( "client.yml" ))

p client2

The error:

/usr/local/lib/ruby/1.8/yaml.rb:133:in `transfer': allocator undefined
for Method (TypeError)
from /usr/local/lib/ruby/1.8/yaml.rb:133:in `load'
from client.rb:11
 
A

Asfand Yar Qazi

Jim said:
The code:

require "http-access2"
require "yaml"

client = HTTPClient.new

File.open("client.yml", "w") do |file|
file.puts client.to_yaml
end

client2 = YAML.load( File.read( "client.yml" ))

p client2

The error:

/usr/local/lib/ruby/1.8/yaml.rb:133:in `transfer': allocator undefined
for Method (TypeError)
from /usr/local/lib/ruby/1.8/yaml.rb:133:in `load'
from client.rb:11

Works fine for me on Ruby 1.8.4

I heard of a yaml bug in Ruby 1.8.3 - I'm assuming that's it.


--
Entry in RollerCoaster Tycoon 2 readme.txt file:
RollerCoaster Tycoon2 must be played on a video card capable of
640x480 screen resolution at a bit depth setting of 256 bits.
And the proof that playing too many strategy games causes loss of humour:
http://tinyurl.com/dyrtt
 
R

Ross Bamford

$ ruby -v
ruby 1.8.4 (2005-12-24) [i686-linux]

I don't think it's a bug, just that HTTPClient has a Method in one of it's
instance variables, and YAML doesn't have a way to load them (rightly so,
of course). Try this:

require "http-access2"
require "yaml"

class HTTPClient
def to_yaml( opts = {} )
YAML.quick_emit( self.id, opts ) { |out|
out.map( "!contrived.cxm,2006-01-05" ) { |map|
instance_variables.sort.each { |iv|
value = instance_eval(iv)
map.add(iv[1..-1], value) unless value.is_a? Method
}
}
}
end
end

YAML.add_domain_type( "contrived.cxm,2006-01-05", "httpClient" ) { |type,
val|
YAML.object_maker( HTTPClient, val )
}

client = HTTPClient.new

File.open("client.yml", "w") do |file|
file.puts client.to_yaml
end

client2 = YAML.load( File.read( "client.yml" ))

p client2

I should say, however, that you really shouldn't use this - the client is
undoubtedly broken (it's not keeping Methods in instance vars for nothing)
so it wouldn't work. It's just to show that's where (I think) the problem
lies.
 
J

Jim

Ross said:
$ ruby -v
ruby 1.8.4 (2005-12-24) [i686-linux]

I don't think it's a bug, just that HTTPClient has a Method in one of it's
instance variables, and YAML doesn't have a way to load them (rightly so,
of course).

I see, that makes sense. I just need to save the parts I'm interested
in - like the cookies. Thanks.
 

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

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top