Class: Module
- Inherits:
-
Object
- Object
- Module
- Defined in:
- lib/extensions/module.rb
Instance Method Summary collapse
-
#abstract(method_name) ⇒ Object
Document methods that MUST be overridden by child classes.
-
#delegate(*methods, to: nil) ⇒ Object
Delegate a set of methods to another object.
-
#overridable(method_name) ⇒ Object
Document methods that CAN or SHOULD be overridden by child classes.
-
#override(method_name) ⇒ Object
Document methods that are overriding a parent class.
Instance Method Details
#abstract(method_name) ⇒ Object
Document methods that MUST be overridden by child classes.
4 5 6 7 8 |
# File 'lib/extensions/module.rb', line 4 def abstract(method_name) define_method(method_name) do fail NotImplementedError end end |
#delegate(*methods, to: nil) ⇒ Object
Delegate a set of methods to another object. This is meant to be a simpler version of Rails' ActiveSupport implementation.
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/extensions/module.rb', line 22 def delegate(*methods, to: nil) fail ArgumentError, "Must specify target of `delegate` using `to` keyword argument." if to.nil? to = to.to_sym to = "self.#{to}" unless to.start_with?("@") methods.each do |method| define_method(method) do |*args| receiver = instance_eval(to) receiver.__send__(method, *args) end end end |
#overridable(method_name) ⇒ Object
Document methods that CAN or SHOULD be overridden by child classes.
11 12 13 |
# File 'lib/extensions/module.rb', line 11 def overridable(method_name) method_name end |
#override(method_name) ⇒ Object
Document methods that are overriding a parent class.
16 17 18 |
# File 'lib/extensions/module.rb', line 16 def override(method_name) method_name end |