Class: Mash

Inherits:
Hash show all
Defined in:
lib/mash.rb

Overview

This class has dubious semantics and we only have it so that people can write params instead of params.

Direct Known Subclasses

GSolr::Ext::Response::Base

Instance Method Summary collapse

Methods inherited from Hash

#to_mash

Constructor Details

#initialize(constructor = {}) ⇒ Mash



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

def initialize(constructor = {})
  if constructor.is_a?(Hash) 
    super() 
    update(constructor) 
  else 
    super(constructor) 
  end 
end

Instance Method Details

#[]=(key, value) ⇒ Object

See Also:

  • #convert_key
  • #convert_value


42
43
44
# File 'lib/mash.rb', line 42

def []=(key, value) 
  regular_writer(convert_key(key), convert_value(value)) 
end

#default(key = nil) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/mash.rb', line 25

def default(key = nil) 
  if key.is_a?(Symbol) && include?(key = key.to_s) 
    self[key] 
  else 
    super 
  end 
end

#delete(key) ⇒ Object



100
101
102
# File 'lib/mash.rb', line 100

def delete(key) 
  super(convert_key(key)) 
end

#dupMash



87
88
89
# File 'lib/mash.rb', line 87

def dup 
  Mash.new(self) 
end

#fetch(key, *extras) ⇒ Object



74
75
76
# File 'lib/mash.rb', line 74

def fetch(key, *extras) 
  super(convert_key(key), *extras) 
end

#key?(key) ⇒ TrueClass, FalseClass Also known as: include?, has_key?, member?



61
62
63
# File 'lib/mash.rb', line 61

def key?(key) 
  super(convert_key(key)) 
end

#merge(hash) ⇒ Mash



94
95
96
# File 'lib/mash.rb', line 94

def merge(hash) 
  self.dup.update(hash) 
end

#regular_updateObject



34
# File 'lib/mash.rb', line 34

alias_method :regular_update, :update

#regular_writerObject



33
# File 'lib/mash.rb', line 33

alias_method :regular_writer, :[]=

#stringify_keys!Mash

Used to provide the same interface as Hash.



107
# File 'lib/mash.rb', line 107

def stringify_keys!; self end

#to_hashHash



110
111
112
# File 'lib/mash.rb', line 110

def to_hash 
  Hash.new(default).merge(self) 
end

#update(other_hash) ⇒ Mash Also known as: merge!



51
52
53
54
# File 'lib/mash.rb', line 51

def update(other_hash) 
  other_hash.each_pair { |key, value| regular_writer(convert_key(key), convert_value(value)) } 
  self 
end

#values_at(*indices) ⇒ Array



82
83
84
# File 'lib/mash.rb', line 82

def values_at(*indices) 
  indices.collect {|key| self[convert_key(key)]} 
end