Module: Overridable::ModuleMixin::ClassMethods
- Defined in:
- lib/overridable.rb
Instance Method Summary collapse
-
#append_features(mod) ⇒ Object
:nodoc:.
-
#overrides(options = {}) ⇒ Object
Whitelist and blacklist for to-be-overrided methods.
Instance Method Details
#append_features(mod) ⇒ Object
:nodoc:
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/overridable.rb', line 90 def append_features mod #:nodoc: # these must be done in `append_features`, not `included` mod.send :include, Overridable methods = if @override_options && !@override_options[:only].empty? @override_options[:only] else all_methods = public_instance_methods + protected_instance_methods + private_instance_methods if @override_options && !@override_options[:except].empty? all_methods - @override_options[:except] else all_methods end end mod.overrides *methods super end |
#overrides(options = {}) ⇒ Object
Whitelist and blacklist for to-be-overrided methods. If this method with the same options is called multiple times within the same module, only the last call will work.
124 125 126 127 128 129 130 131 |
# File 'lib/overridable.rb', line 124 def overrides = {} raise ArgumentError, "Only :only and :except options are accepted." unless .keys.all? { |k| [:only, :except].include? k } @override_options ||= {:only => [], :except => []} @override_options[:only] = [[:only]].flatten.compact if [:only] @override_options[:except] = [[:except]].flatten.compact if [:except] @override_options[:only] = @override_options[:only] - @override_options[:except] end |