Esta apresentação foi ministrada em um curso de desenvolvimento e a traz uma dinâmica acerca da implementação do algoritmo de method lookup e constant lookup do ruby.
reload(chargeable) chargeable.energy = 100 end end class Robot def reload_battery() Charger.new.reload(self) end def energy=(amount) @energy += amount end end
Interface other objects may interact through this API usually defined as: class MyObject # … # … end The PRIVATE interface no external access STABLE API shouldn’t change frequently UNSTABLE API may change frequently
# ... end end How to deal with interfaces: My Object Interface other objects may interact through this API no external access STABLE API shouldn’t change frequently UNSTABLE API may change frequently
Object class BasicObject class respond to #method ??? maybe you respond to #method ? and what about you? long and patient lookup…. please… help... OK! my life is a lie, BYE!
grandpa class Object class BasicObject class respond to #method ??? maybe you respond to #method ? and what about you? long and patient lookup…. please… help...
class respond to #method ??? maybe you respond to #method ? and what about you? long and patient lookup…. please… help... OOPS! Let’s try again! Method dispatch algorithm (Part 1)
class OK! my life is a lie, BYE! respond to #method ??? maybe you respond to #method ? and what about you? long and patient lookup…. please… help... OOPS! Let’s try again! call method_missing! now you... and falls into the loop again. OK! Your last chance! Method dispatch algorithm (Full view)