[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Is this a YAML bug?

Jim

1/4/2006 2:26:00 PM

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

4 Answers

Asfand Yar Qazi

1/5/2006 3:13:00 PM

0

Jim wrote:
> 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...

Jim

1/5/2006 4:10:00 PM

0

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

Ross Bamford

1/5/2006 11:19:00 PM

0

On Thu, 05 Jan 2006 16:09:39 -0000, Jim <narf968@gmail.com> wrote:

> $ 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.

--
Ross Bamford - rosco@roscopeco.remove.co.uk

Jim

1/11/2006 7:46:00 PM

0


Ross Bamford wrote:
> On Thu, 05 Jan 2006 16:09:39 -0000, Jim <narf968@gmail.com> wrote:
>
> > $ 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).
> --
> Ross Bamford - rosco@roscopeco.remove.co.uk

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