Class: EacRubyUtils::Compact

Inherits:
Object
  • Object
show all
Defined in:
lib/eac_ruby_utils/compact.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#attributesObject (readonly)

Returns the value of attribute attributes.



5
6
7
# File 'lib/eac_ruby_utils/compact.rb', line 5

def attributes
  @attributes
end

#objectObject (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_aArray

Returns:

  • (Array)


13
14
15
# File 'lib/eac_ruby_utils/compact.rb', line 13

def to_a
  attributes.map { |attr| object.send(attr) }
end

#to_hHash

Returns:



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