Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Techtalk - My method is missing!

Techtalk - My method is missing!

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.

Avatar for Gabriel Leopoldo Ferreira

Gabriel Leopoldo Ferreira

January 22, 2020

More Decks by Gabriel Leopoldo Ferreira

Other Decks in Technology

Transcript

  1. Message Oriented Design - Example class Charger # … def

    reload(chargeable) chargeable.energy = 100 end end class Robot def reload_battery() Charger.new.reload(self) end def energy=(amount) @energy += amount end end
  2. A troca de mensagens é muito mais impactante na definição

    de uma arquitetura que os objetos participantes
  3. How to deal with interfaces: The PUBLIC interface My Object

    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
  4. class Robot def do_things() # ... end private def check_battery()

    # ... 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
  5. class Robot def do_things() # ... end def check_battery() #

    ... end def self.create() # ... end end Lexical Scopes Robot object scope class Robot scope
  6. class Robot def self.do_things() # ... end def self.check_battery() #

    ... end private def self.create() # ... end end Lexical Scopes Robot object scope class Robot scope
  7. class Robot class << self def do_things() # ... end

    private def self.create() # ... end end end Lexical Scopes Robot object scope class Robot scope
  8. Method dispatch algorithm ... ruby object parent class grandpa class

    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!
  9. Method dispatch algorithm (Part 1) ... ruby object parent class

    grandpa class Object class BasicObject class respond to #method ??? maybe you respond to #method ? and what about you? long and patient lookup…. please… help...
  10. ... ruby object parent class grandpa class Object class BasicObject

    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)
  11. ... ruby object parent class grandpa class Object class BasicObject

    class call method_missing! now you... and falls into the loop again. OK! Your last chance! Method dispatch algorithm (Part 2)
  12. ... ruby object parent class grandpa class Object class BasicObject

    class OK! my life is a lie, BYE! Method dispatch algorithm (Part 2)
  13. ... ruby object parent class grandpa class Object class BasicObject

    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)