Mathieu Bouchard ha scritto: >> I guess perl folks too, since an object is mostly an hash (I may be >> wrong, not really good at perl). > > > No: in Perl, a hash can contain anonymous subs (that is like Ruby > procs), but the method lookup is a different thing. <snip> sorry, I did not intend that you could handle they the same way. I was justthinking that in python an object is basically an hash (actually visible from it's __dict__ attribute) and that there is some magic for the calling. Since I recall that perl's OO was inspired from python I was *guessing* there could be a similar mechanic. >> Actually, only Java's anonymous classes seem somewhat similar to >> singleton ones. > > > They are not. They are a special case of inner classes, and inner > classes blend the concepts of class, delegation, and closure, all > together, but nothing in Java is singleton. But still I am curious: > could you please provide a snippet in which you emulate singleton > behaviour using Java's anonymous classes? I was thinking of: Object a= new Object() { public String toString(){ return "method ovverriden for this single object"; } }; System.out.println(a); // => method ovverriden for this single object like in ruby lookup happens like: - loon in singleton class - then in superclasses in java the lookup becomes - look in anonymous class - then in its superclasses