From: ara.t.howard@... Date: 2006-05-27T04:35:29+09:00 Subject: Re: Marshaling NArray objects. On Sat, 27 May 2006, Alex Polite wrote: > On 5/25/06, ara.t.howard@noaa.gov wrote: >> >> are you sure need it? > > yeah. I'm marshaling objects that have narrays as a component among others. >> >> harp:~ > cat a.rb >> require 'narray' >> >> class NArray >> def _dump *ignored >> Marshal.dump :typecode => typecode, :shape => shape, :data => to_s >> end >> def self._load buf >> h = Marshal.load buf >> typecode = h[:typecode] >> shape = h[:shape] >> data = h[:data] >> to_na data, typecode, *shape >> end >> end >> > > Thanks a bunch. That did the trick. Just one more thing. When I load a > marshalled object I can access the attributes on that object but I can > call it's methods. This is from irb. I've googled for stuff like > "marshaling methods" to no avail. > > Alex you must have something else going on, you needn't do anything special to marshal methods: harp:~ > cat a.rb require 'narray' class NArray def _dump *ignored Marshal.dump :typecode => typecode, :shape => shape, :data => to_s end def self._load buf h = Marshal.load buf typecode = h[:typecode] shape = h[:shape] data = h[:data] to_na data, typecode, *shape end end na = Marshal.load(Marshal.dump(NArray.int(4,2))) p na na[true, 0] = 42 p na p na.size p na.shape harp:~ > ruby a.rb NArray.int(4,2): [ [ 0, 0, 0, 0 ], [ 0, 0, 0, 0 ] ] NArray.int(4,2): [ [ 42, 42, 42, 42 ], [ 0, 0, 0, 0 ] ] 8 [4, 2] you'll have to show us your problem - probably you are returning the wrong kind of object from the class _load method. regards. -a -- be kind whenever possible... it is always possible. - h.h. the 14th dali lama