Module: RakeCommander::Base::ClassInheritable
- Includes:
- ObjectHelpers
- Defined in:
- lib/rake-commander/base/class_inheritable.rb
Instance Method Summary collapse
-
#attr_inheritable(*attrs, add_accessors: false, deep_dup: true) {|value| ... } ⇒ Object
Builds the attr_reader and attr_writer of
attrs
and registers the associated instance variable as inheritable. -
#attr_not_inheritable(*attrs) ⇒ Object
Removes from the inheritance some class variables.
-
#inheritable_class_var?(var) ⇒ Boolean
Whether an
var
has been declared as inheritable.
Instance Method Details
#attr_inheritable(*attrs, add_accessors: false, deep_dup: true) {|value| ... } ⇒ Object
Builds the attr_reader and attr_writer of attrs
and registers the associated
instance variable as inheritable.
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/rake-commander/base/class_inheritable.rb', line 14 def attr_inheritable(*attrs, add_accessors: false, deep_dup: true, &block) attrs = attrs.map(&:to_sym) inheritable_class_var(*attrs, deep_dup: deep_dup, &block) return unless add_accessors attrs.each do |attr| class_eval <<-RUBY, __FILE__, __LINE__ + 1 class << self; attr_accessor :#{attr} end RUBY end self end |
#attr_not_inheritable(*attrs) ⇒ Object
Removes from the inheritance some class variables.
36 37 38 39 40 41 42 |
# File 'lib/rake-commander/base/class_inheritable.rb', line 36 def attr_not_inheritable(*attrs) attrs.each do |attr| next unless method = inheritable_class_var_method(attr) inheritable_class_var[method].delete(attr) end self end |
#inheritable_class_var?(var) ⇒ Boolean
Returns whether an var
has been declared as inheritable.
27 28 29 30 31 |
# File 'lib/rake-commander/base/class_inheritable.rb', line 27 def inheritable_class_var?(var) inheritable_class_var.any? do |_method, definitions| definitions.key?(var.to_sym) end end |