Class: Array

Inherits:
Object show all
Defined in:
lib/subtle/array_to_hashes.rb,
lib/subtle/array_to_objects.rb

Instance Method Summary collapse

Instance Method Details

#to_hashes(test = nil, &block_that_returns_the_records) ⇒ Object



3
4
5
6
7
# File 'lib/subtle/array_to_hashes.rb', line 3

def to_hashes(test = nil, &block_that_returns_the_records)
  records = block_that_returns_the_records.call
  return [] if records.empty?
  records.map { |record| turn_this_data_into_a_filled_hash(record) }
end

#to_object(subject = Object.new) ⇒ Object



3
4
5
6
# File 'lib/subtle/array_to_objects.rb', line 3

def to_object(subject = Object.new)
  self.each { |field| add_attr_accessor_for(subject, field) }
  subject
end

#to_objects(type = Object, &block_that_returns_the_records) ⇒ Object



8
9
10
11
12
# File 'lib/subtle/array_to_objects.rb', line 8

def to_objects(type = Object, &block_that_returns_the_records)
  records = block_that_returns_the_records.call
  return [] if records.empty?
  records.map { |record| turn_this_data_into_a_filled_object(type, record) }
end