Class: Hash

Inherits:
Object
  • Object
show all
Defined in:
lib/ignition/core/hash.rb

Direct Known Subclasses

Ignition::Bundle, Ignition::BundleStatus

Class Method Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(key, value = nil) ⇒ Object

def accessed

@accessed.uniq

end



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/ignition/core/hash.rb', line 14

def method_missing(key,value = nil)
  # puts "method_missing"
  # puts key
  # puts value
  if self.has_key?(key)
    self[key]    
  elsif self.has_key?(key.to_s)
    # if @record_access
    #   puts "here #{key.to_s }"
    #   puts @accessed.nil?
    #   @accessed << key.to_s 
    # end
    self[key.to_s]
  elsif key.to_s.include?("=")
    self[key.to_s.gsub("=","")] = value
  else
    super
  end
end

Class Method Details

.zip(keys, values, default = nil, &block) ⇒ Object



40
41
42
43
44
# File 'lib/ignition/core/hash.rb', line 40

def self.zip(keys, values, default=nil, &block)
  hsh = block_given? ? Hash.new(&block) : Hash.new(default)
  keys.zip(values) { |k,v| hsh[k]=v }
  hsh
end

Instance Method Details

#except(*keys) ⇒ Object

def empty?

(count == 0)

end



65
66
67
# File 'lib/ignition/core/hash.rb', line 65

def except(*keys)
  dup.except!(*keys)
end

#except!(*keys) ⇒ Object

Replaces the hash without the given keys.



70
71
72
73
# File 'lib/ignition/core/hash.rb', line 70

def except!(*keys)
  keys.each { |key| delete(key) }
  self
end

#remove_emptyObject



34
35
36
37
38
# File 'lib/ignition/core/hash.rb', line 34

def remove_empty
  delete_if do |k, v|
    v.nil?
  end
end