Class: Shash
- Inherits:
-
Object
show all
- Defined in:
- lib/shash.rb,
lib/version.rb
Constant Summary
collapse
- MAJOR =
0
- MINOR =
0
- BUILD =
7
- VERSION =
"#{MAJOR}.#{MINOR}.#{BUILD}"
Instance Method Summary
collapse
Constructor Details
#initialize(hash = {}) ⇒ Shash
Returns a new instance of Shash.
2
3
4
5
|
# File 'lib/shash.rb', line 2
def initialize(hash={})
@hash = {}
init!(hash)
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(key, *args, &block) ⇒ Object
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
# File 'lib/shash.rb', line 7
def method_missing(key, *args, &block)
if key[/=$/]
self[key[0...-1]] = args.first
else
if @hash.key?(key)
@hash[key]
else
begin
@hash.send(key, *args, &block)
rescue NoMethodError
nil
end
end
end
end
|
Instance Method Details
#==(other) ⇒ Object
23
24
25
|
# File 'lib/shash.rb', line 23
def ==(other)
other == @hash
end
|
#[]=(key, value) ⇒ Object
27
28
29
|
# File 'lib/shash.rb', line 27
def []=(key,value)
@hash[key.respond_to?(:to_sym) ? key.to_sym : key] = shashify(value)
end
|