Class: TrackingNumber::Info

Inherits:
Object
  • Object
show all
Defined in:
lib/tracking_number/info.rb

Instance Method Summary collapse

Constructor Details

#initialize(info_hash = {}) ⇒ Info

Returns a new instance of Info.



3
4
5
6
7
8
9
10
11
12
# File 'lib/tracking_number/info.rb', line 3

def initialize(info_hash = {})
  info_hash.keys.each do |key|
    self.instance_variable_set("@#{key}", info_hash[key])
    self.class_eval { attr_accessor key }
  end

  if info_hash.keys.size == 1
    @default = info_hash[info_hash.keys.first]
  end
end

Instance Method Details

#to_sObject



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

def to_s
  @default || @name
end