Module: WrapIt::DerivedAttributes::ClassMethods
- Included in:
- WrapIt::DerivedAttributes
- Defined in:
- lib/wrap_it/derived_attributes.rb
Overview
WrapIt::DerivedAttributes class methods
Instance Method Summary collapse
-
#collect_derived(name, result = [], method = :concat) ⇒ Object
Collects all derived variables with specified name.
-
#get_derived(name) ⇒ Object?
retrieves first founded derived variable or nil.
- #parents ⇒ Object
Instance Method Details
#collect_derived(name, result = [], method = :concat) ⇒ Object
Collects all derived variables with specified name
49 50 51 52 53 54 55 |
# File 'lib/wrap_it/derived_attributes.rb', line 49 def collect_derived(name, result = [], method = :concat) parents.select { |p| p.instance_variable_defined?(name) } .each do |p| result = result.send(method, p.instance_variable_get(name)) end result end |
#get_derived(name) ⇒ Object?
retrieves first founded derived variable or nil
31 32 33 34 35 36 37 38 39 |
# File 'lib/wrap_it/derived_attributes.rb', line 31 def get_derived(name) return instance_variable_get(name) if instance_variable_defined?(name) ancestors.each do |ancestor| next unless ancestor.instance_variable_defined?(name) break if ancestor == Base return ancestor.instance_variable_get(name) end nil end |
#parents ⇒ Object
22 23 24 |
# File 'lib/wrap_it/derived_attributes.rb', line 22 def parents @parents ||= ancestors.take_while { |a| a != Base }.concat([Base]) end |