From: Eloy D. <elo...@gm...> - 2007-10-26 09:34:21
|
Well you could also do somewhere: class Object def to_ruby self end end This will make sure that #to_ruby can be called on any object. Eloy On 10/26/07, Javier Solorzano <jav...@ri...> wrote: > Eloy, > > The problem is that when the hash or array holds values that have > been mutated into cocoa variants, the marshal will fail, so I have to > deeply transverse the data structure making sure each and every > number, string array and hash held inside is in fact a ruby object > just before issuing the marshal dump message. Moreover, I can't > just use #to_ruby because ruby objects don't understand that message, > so I end up using to_i, to_f, to_array, .. on each object in the data > structure to replace it with ruby objects when I know beforehand what > type to expect and #class in a switch statement when I don't to > decide what type to transform it into. Jeez, looks more like java and > type coercing and less like Ruby. > > Perhaps I should extend cocoa objects with marshal messages that save > and load ruby classes? > > JS > > Hi Javier, > > This is intended behaviour. Ruby arrays and hashes etc do not have > what it takes to be able to use with bindings etc. Don't worry about > it to much, you can ducktype most of the stuff. > > You can always use #to_hash or #to_a: > Marshal.dump(ns_dict.to_hash) > > Or if you are ducktyping you can use #to_ruby which resolves the ruby > variants of the objects that you have: > > Marshal.dump(obj.to_ruby) > > Cheers, > Eloy > > ------------------------------------------------------------------------- > This SF.net email is sponsored by: Splunk Inc. > Still grepping through log files to find problems? Stop. > Now Search log events and configuration files using AJAX and a browser. > Download your FREE copy of Splunk now >> http://get.splunk.com/ > _______________________________________________ > Rubycocoa-talk mailing list > Rub...@li... > https://lists.sourceforge.net/lists/listinfo/rubycocoa-talk > |