From: "Victor \"Zverok\" Shepelev" Date: 2007-06-28T07:43:05+09:00 Subject: Re: Fun about inspect From: Robert Klemme [mailto:shortcutter@googlemail.com] Sent: Wednesday, June 27, 2007 1:40 PM >On 26.06.2007 23:42, Victor "Zverok" Shepelev wrote: >> >> By some complex reasons, I've made an interesting conclusion: for >> "serializable" types it's always good to have eval(obj.inspect) == obj >> >> For me it was a good thought, because previously, I've always doubt what >> #inspect should do, and typically have ended with #inspect as alias for >> #to_s >> [...] >> >> There are several interesting things to note: >> * basic types (Numeric, String, Array, Hash) are all behave good here. > >No, they don't. See below. > [...] >> >> What do you think? > >I think nobody should rely on #inspect creating something that will be >able to resurrect the original. Note, that it does not even work >properly for Hashes: [...] There is a bit of misunderstanding. I'm not talking about some "strict rules". I've just suggested a "rule of thumb" for designing #inspect. Of course, there can be different cases and so on, but typically and especially for "data" objects (those whose data is more important than behavior) it's good to have object inspect-"restorable" at some level (even not in full, as in your smart example about Hash). V.