Class: EacRubyUtils::Compact
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
-
#object ⇒ Object
readonly
Returns the value of attribute object.
Instance Method Summary collapse
-
#initialize(object, attributes) ⇒ Compact
constructor
A new instance of Compact.
- #to_a ⇒ Array
- #to_h ⇒ Hash
Constructor Details
#initialize(object, attributes) ⇒ Compact
Returns a new instance of Compact.
7 8 9 10 |
# File 'lib/eac_ruby_utils/compact.rb', line 7 def initialize(object, attributes) @object = object @attributes = attributes end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
5 6 7 |
# File 'lib/eac_ruby_utils/compact.rb', line 5 def attributes @attributes end |
#object ⇒ Object (readonly)
Returns the value of attribute object.
5 6 7 |
# File 'lib/eac_ruby_utils/compact.rb', line 5 def object @object end |
Instance Method Details
#to_a ⇒ Array
13 14 15 |
# File 'lib/eac_ruby_utils/compact.rb', line 13 def to_a attributes.map { |attr| object.send(attr) } end |
#to_h ⇒ Hash
18 19 20 |
# File 'lib/eac_ruby_utils/compact.rb', line 18 def to_h attributes.map { |attr| [attr.to_sym, object.send(attr)] }.to_h end |