Class: DataContainer

Inherits:
Struct
  • Object
show all
Defined in:
lib/data_container.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.new(*args) ⇒ Object



2
3
4
# File 'lib/data_container.rb', line 2

def self.new(*args)
  super.new    # send back an INSTANCE, not a class
end

Instance Method Details

#get(ivar) ⇒ Object



6
7
8
# File 'lib/data_container.rb', line 6

def get(ivar)
  send(ivar) if include?(ivar)
end

#include?(var) ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/data_container.rb', line 28

def include?(var)
  data.include?(var.to_sym)
end

#inspectObject



18
19
20
# File 'lib/data_container.rb', line 18

def inspect
  '#<DataContainer: ' + variable_value_pairs_string.join(' ') + '>'
end

#merge!(other_data_container) ⇒ Object



22
23
24
25
26
# File 'lib/data_container.rb', line 22

def merge!(other_data_container)
  other_data_container.each_pair do |var, val|
    set(var, val) unless val.nil?
  end
end

#populate_from_hash(hash) ⇒ Object



32
33
34
# File 'lib/data_container.rb', line 32

def populate_from_hash(hash)
  hash.each { |var, val| set(var, val) }
end

#set(ivar, value) ⇒ Object



10
11
12
# File 'lib/data_container.rb', line 10

def set(ivar, value)
  send("#{ivar}=", value) if include?(ivar)
end

#to_sObject



14
15
16
# File 'lib/data_container.rb', line 14

def to_s
  '@' + variable_value_pairs_string.join(', @')
end