Sometimes we open a class without knowing us. For example, with a certain depth of nesting of modules:
# space_gun.rb class SpaceGun << Weapon def fire Trigger.fire end end
When we define a trigger, we open the existing SpaceGun class. It works. However, if we upload two files in the reverse order, the error will be raised because we first define the SpaceGun class, but are not weapons.
Sometimes we make this mistake because we explicitly require that a module (for example, a trigger) be subordinate from a module of the parent class. This means that the class definition will be done in the reverse order, which will cause this problem.
# surely nothing can go wrong if we require what we need first right? require 'space_gun/trigger' class SpaceGun << Weapon def fire Trigger.fire end end
Or
- rely on automatic downloads
- always puts inheritance in every open class event.
lulalala Jul 13 '16 at 5:32 2016-07-13 05:32
source share