Class: Mash
- Inherits:
-
Hash
show all
- Defined in:
- lib/mash.rb
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
2
3
4
5
6
7
8
9
10
11
12
|
# File 'lib/mash.rb', line 2
def method_missing name, *args, &block
if name.to_s =~ /(.*)=/
self.[]=($1, *args, &block)
else
if args.empty?
self.[](name, &block)
else
self.[]=(name, *args, &block)
end
end
end
|
Instance Method Details
#[](k) {|v| ... } ⇒ Object
19
20
21
22
23
|
# File 'lib/mash.rb', line 19
def [](k)
v = super(k.to_s.downcase.to_sym)
yield v if block_given?
v
end
|
#[]=(k, *v) ⇒ Object
14
15
16
17
|
# File 'lib/mash.rb', line 14
def []=(k, *v)
v = *v if v.one?
super k.to_s.downcase.to_sym, v
end
|