3 Practical Uses of Ruby's `method_missing`.

Learn the practical uses of Ruby's method_missing. You can use the method_missing method to handle errors, delegate methods and build DSLs.We define methods inside classes. Ruby traverses a method lookup path when an object calls a method, starting from the object’s class and up the object’s class’s ancestor chain to reach the method. If the method the object calls is available in the lookup path, Ruby calls it. On some occasions, the method isn’t present in the ancestor chain.All method lookups that fail end up reaching a method called method_missing. method_missing lives inside the BasicOjbect class, the root of all classes.For a class, Aircraft, that mixes in no other modules or prepends other module or inherit other classes, this is how the traversal would look like (I’ve omitted the lookup through eigenclasses for simplicity):.
3 Practical Uses of Ruby's `method_missing`. #ruby #rubydeveloper #rubyonrails https://rubyonrails.ba/single/3-practical-uses-of-ruby-s-method_missing

Nezir Zahirovic

Contractor Ruby On Rails (8+ years) / MCPD .Net / C# / Asp.Net / CSS / SQL / (11 years)

related articles