From: Adam Shelly Date: 2005-08-31T10:18:31+09:00 Subject: beginners YAML question ------=_Part_5_29069532.1125451108547 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline I needed a class that acted like a container, as well as doing other things= .=20 I tried making it a subclass of Array, instead of adding an Array member. I= t=20 was working fine until I tried to reload it from YAML. Here is some code=20 that reproduces the problem. It seems like the Size parameter is not being= =20 output in the YAML string.=20 - Why doesn't it work? - How can I make it work? ---- require 'Yaml' class Box< Array def initialize size @size =3D size end def size @size end end box =3D Box.new (2) box << "orange" box_yaml =3D box.to_yaml p box_yaml # prints "--- !ruby/array:Box \n- orange" box2 =3D YAML::load(box_yaml) # produces: =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D ArgumentError =3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=20 c:\ruby\lib\ruby\1.8/yaml/rubytypes.rb:239:in `initialize'=20 o =3D obj_class.new=20 c:\ruby\lib\ruby\1.8/yaml/rubytypes.rb:239:in `new'=20 o =3D obj_class.new=20 c:\ruby\lib\ruby\1.8/yaml/rubytypes.rb:239=20 o =3D obj_class.new=20 c:\ruby\lib\ruby\1.8/yaml/rubytypes.rb:235:in `call'=20 array_proc =3D Proc.new { |type, val|=20 c:\ruby\lib\ruby\1.8/Yaml.rb:119:in `transfer'=20 yp =3D @@parser.new.load( io )=20 c:\ruby\lib\ruby\1.8/Yaml.rb:119:in `load'=20 yp =3D @@parser.new.load( io )=20 c:\ruby\lib\ruby\1.8/Yaml.rb:119:in `load'=20 yp =3D @@parser.new.load( io )=20 c:\ruby\lib\ruby\1.8\test.rb:21=20 box2 =3D YAML::load(box_yaml)=20 c:\ruby\lib\ruby\site_ruby\1.8/rubygems/custom_require.rb:18:in `require__'= =20 require__ path=20 c:\ruby\lib\ruby\site_ruby\1.8/rubygems/custom_require.rb:18:in `require'= =20 require__ path=20 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=20 Exception: wrong number of arguments (0 for 1)=20 Thanks, -Adam ------=_Part_5_29069532.1125451108547--