Class: HashTable::HashLine

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

Direct Known Subclasses

GTF::GTFLine

Instance Method Summary collapse

Constructor Details

#initialize(h) ⇒ HashLine

Returns a new instance of HashLine.



12
13
14
15
16
17
18
# File 'lib/hash_table.rb', line 12

def initialize h
  if h.is_a? Array
    @hash = Hash[h]
  elsif h.is_a? Hash
    @hash = h
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *args, &block) ⇒ Object



44
45
46
47
48
49
50
51
52
# File 'lib/hash_table.rb', line 44

def method_missing sym, *args, &block
  if @hash[sym]
    @hash[sym]
  elsif sym.to_s =~ /(.*)=/ 
    @hash[$1.to_sym] = args.first
  else
    nil
  end
end

Instance Method Details

#[](ind) ⇒ Object



24
25
26
# File 'lib/hash_table.rb', line 24

def [] ind
  @hash[ind]
end

#[]=(ind, v) ⇒ Object



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

def []= ind,v
  @hash[ind] = v
end

#approve!Object



36
37
38
# File 'lib/hash_table.rb', line 36

def approve!
  @invalid = nil
end

#invalid?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/hash_table.rb', line 40

def invalid?
  @invalid
end

#invalidate!Object



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

def invalidate!
  @invalid = true
end

#update(hash) ⇒ Object



20
21
22
# File 'lib/hash_table.rb', line 20

def update hash
  @hash.update hash
end