[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Creating classes with from YAML?

David Garamond

9/23/2003 7:02:00 PM

Remembering that all classes are instances of the Class class, is this
possible? I want to create some class named, say C1, which is empty (or
perhaps with one or two class instance vars) by loading a YAML document.
I can't seem to create instances of Class class in YAML, while I can
easily do this in irb:

$ irb
irb(main):001:0> C1=Class.new
=> C1
irb(main):002:0> C1.new
=> #<C1:0x40174a1c>

--
dave



1 Answer

Eric Hodel

9/23/2003 7:11:00 PM

0

David Garamond (lists@zara.6.isreserved.com) wrote:

> Remembering that all classes are instances of the Class class, is this
> possible? I want to create some class named, say C1, which is empty (or
> perhaps with one or two class instance vars) by loading a YAML document.
> I can''t seem to create instances of Class class in YAML, while I can
> easily do this in irb:

irb(main):002:0> 5.to_yaml
=> "--- 5"
irb(main):003:0> Class.to_yaml
ArgumentError: can''t dump anonymous class Class
from /usr/local/lib/ruby/1.8/yaml/rubytypes.rb:8:in `to_yaml''
from (irb):3
irb(main):004:0> class Foo; end
=> nil
irb(main):005:0> Foo.to_yaml
ArgumentError: can''t dump anonymous class Class
from /usr/local/lib/ruby/1.8/yaml/rubytypes.rb:8:in `to_yaml''
from (irb):5

Does not appear possible to do with Yaml, but you can with Marshal:

irb(main):007:0> Marshal.dump(Foo)
=> "\004\010c\010Foo"


--
Eric Hodel - drbrain@segment7.net - http://se...
All messages signed with fingerprint:
FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04