On Friday 13 July 2012, Weston Platter wrote: > What's the benefit and/or difference between > Forem's controller/model Module::Class.class_eval strategy > Wicked Wizard ActiveSupport::Concern strategy
The first, reopening a class and defining methods, just adds new methods by adding them to the class. If there already was a method of the same name, it is redefined. The later, including a concern in an existing class, adds methods by including a module containing them. This module is inserted into the inheritance chain just above the class itself but before any superclasses and previously included modules. Therefore, methods defined in such a module override those in the inheritance chain, but can access them through super. However, methods defined in the including class itself take precedence over those in any included module. As such, IMO, the best way to ensure extensibility of a class is to define its functionality in modules and have the class itself contain barely more that a list of includes. That way, extensions can be included from new modules while still keeping the original functionality accessible to them. In particular, this avoids renaming methods with alias_method_chain or similar. Michael -- Michael Schuerig mailto:[email protected] http://www.schuerig.de/michael/ -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
