Posted By

ctfarp on 06/04/14


Tagged

rails ruby


Versions (?)

A Method swapping between objects in ruby (method swizzle)


 / Published in: Ruby
 

  1. objective C has a weired feature, it can swaps 2 methods between objects, so if you are trying to call a Method1 from Object1 it will call Method2 from Object2, i created a solution for that in ruby as there is no native implementation in our lovely language, but Matz Gave us a great dynamic language to hack in to.
  2. first i aliased the two methods in the classes of the two objects then i reimplemented the two methods in objects to call the other method.
  3. this way you can swap methods between objects and as Classes itself is an object it self we can swap the new method or any other class method :D

Report this snippet  

You need to login to post a comment.