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

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object



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

def method_missing(name, *args)
  self.instance_variable_get("@#{name}")
end

Instance Method Details

#to_jsonObject



22
23
24
# File 'lib/tracking_number/info.rb', line 22

def to_json

end

#to_sObject



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

def to_s
  @default || @name
end