Class: Hashing::IvarCollection

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/hashing/ivar_collection.rb

Overview

Represents an ivar in a class that includes Hashing which contains a collection of other Hashing instances.

Since:

  • 0.0.1

Instance Method Summary collapse

Constructor Details

#initialize(collection_holder_ivar, type) ⇒ IvarCollection

Returns a new instance of IvarCollection.

Since:

  • 0.0.1



8
9
10
11
# File 'lib/hashing/ivar_collection.rb', line 8

def initialize(collection_holder_ivar, type)
  @holder = collection_holder_ivar
  @type = type
end

Instance Method Details

#from_hash(value) ⇒ Object

Since:

  • 0.0.1



19
20
21
# File 'lib/hashing/ivar_collection.rb', line 19

def from_hash(value)
  @holder.from_hash value.map { |item| @type.from_hash item }
end

#to_h(value) ⇒ Object

Since:

  • 0.0.1



13
14
15
16
17
# File 'lib/hashing/ivar_collection.rb', line 13

def to_h(value)
  @holder.to_h value.map { |item|
    item.respond_to?(:to_h) ? item.to_h : item
  }
end