Class: Dictionary

Inherits:
Object
  • Object
show all
Defined in:
lib/has_dictionary/dictionary.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, description) ⇒ Dictionary

Returns a new instance of Dictionary.



4
5
6
7
# File 'lib/has_dictionary/dictionary.rb', line 4

def initialize id, description
     @id = id
     @description = description
end

Instance Attribute Details

#descriptionObject (readonly)

Returns the value of attribute description.



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

def description
  @description
end

#idObject (readonly)

Returns the value of attribute id.



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

def id
  @id
end

Class Method Details

.add_item(key, value) ⇒ Object



9
10
11
12
# File 'lib/has_dictionary/dictionary.rb', line 9

def self.add_item(key,value)
    @hash ||= {}
    @hash[key]=value
end

.const_missing(key) ⇒ Object



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

def self.const_missing(key)
    @hash[key]
end

.eachObject



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

def self.each
    @hash.each {|key,value| yield(key,value)}
end

.get(key = nil) ⇒ Object



22
23
24
25
26
27
28
29
30
31
# File 'lib/has_dictionary/dictionary.rb', line 22

def self.get key=nil
	if key.nil?
		status=[]
     each { |k,v| status << new(v,k[0..-1]) }
     status
	else
		each { |k,v| return new(v,k[0..-1]) if v==key  }
	end
	
end