tag:blogger.com,1999:blog-4451657389087868432.post6317552816679896580..comments2023-05-29T02:10:01.374-06:00Comments on sworldwatch: Modifying core method behavior without touching core codeAlfred Sawatzkyhttp://www.blogger.com/profile/15845723068853240174noreply@blogger.comBlogger4125tag:blogger.com,1999:blog-4451657389087868432.post-13031917921540807442015-11-23T03:46:27.162-07:002015-11-23T03:46:27.162-07:00With Smallworld 5.0 (SWV) the method define_method...With Smallworld 5.0 (SWV) the method define_method_synonym() has been removed, indeed, but my variant still works. This holds even for methods on a record exemplar. In this case instead of writing:<br /><br /> t.descriptor.record_class.define_method_synonym(:|orig!my_field<<|,:|my_field<<|)<br /><br />you now have to write:<br /> <br /> _method my_class_name.orig!my_field << new_val<br /> _endmethod<br /><br /> my_class_name.method(:|orig!my_field<<|).value << t.descriptor.record_class.method(:|my_field<<|).valueReinhard Hahnnoreply@blogger.comtag:blogger.com,1999:blog-4451657389087868432.post-91528894479606009342011-01-14T03:19:53.976-07:002011-01-14T03:19:53.976-07:00Hi Alfred,
I just found out an a bit more sophisi...Hi Alfred,<br /><br />I just found out an a bit more sophisiticated application of the define_method_synonym() method:<br /><br />For debugging purposes I wanted to know, on which way a certain attribute is set. Therefore I wanted to place a !traceback!(!output!) within the chevronned method of the field. The problem is, that I didn't find a possibility to define a method on the table's record_exemplar directly. (With 'record_exemplar' I mean that automatically generated class with that arbitrary number at the end of the class name.)<br /><br />What I did is the following:<br /><br /><br /> t << gis_program_manager.cached_dataset(:my_view_name).collection(:my_class_name)<br /> $<br /> t.descriptor.record_class.define_method_synonym(:|orig!my_field<<|,:|my_field<<|)<br /> $<br /> _method my_class_name.changed!my_field<< new_val<br /> !traceback!(!output!)<br /> _return _self.orig!my_field<< new_val<br /> _endmethod<br /> $<br /> t.descriptor.record_class.method(:|my_field<<|).value << <br /> my_class_name.method(:|changed!my_field<<|).value<br /> $<br /><br /><br />The trick is, that the method :|changed!my_value<<| isn't originally defined on that record_exemplar. But the last line of the code, assigns the value of that method (which is a procedure) to the value of the method on the record_exemplar.<br /><br />Cheers<br />ReinhardReinhard Hahnnoreply@blogger.comtag:blogger.com,1999:blog-4451657389087868432.post-26154846365380048492010-04-15T09:34:55.949-06:002010-04-15T09:34:55.949-06:00Hi John,
Reinhard Hahn suggested a way around thi...Hi John,<br /><br />Reinhard Hahn suggested a way around this potential problem with define_method_synonym() being "severely deprecated"...<br /><br /><br />If the method :define_method_synonym() ever disappears, you could use the technique, I used up to now:<br /><br /> _method receiver_class.method_name!old(arg1, arg2, _optional arg3, _gather more)<br /> ## copy of _self.method_name()<br /><br /> # no code at all at this place!<br /> _endmethod<br /> $<br /> receiver_class.method(:|method_name!old()|).value << receiver_class.method(:|method_name()|).value<br /> $<br /><br />which should be exactly equivalent to<br /><br /> receiver_class.define_method_synonym(:|method_name!old()|,:|method_name()|)<br /><br />, if you have choosen exactly the same signature of your method.Alfred Sawatzkyhttps://www.blogger.com/profile/15845723068853240174noreply@blogger.comtag:blogger.com,1999:blog-4451657389087868432.post-52501164046132318102009-05-21T14:00:44.462-06:002009-05-21T14:00:44.462-06:00Alfred, I am looking at using this, it will work p...Alfred, I am looking at using this, it will work perfectly. Interesting note though: if you look at the comments for define_method_synonym, they say:<br />"Use of this method is severely deprecated. It defines a<br />second method which does the same thing as the first."<br />Not sure what a SEVERELY deprecated method means, I guess it's way more deprecated than a normally deprecated method.John Fowlernoreply@blogger.com