Class: MultiRedis::Data
- Inherits:
-
Object
- Object
- MultiRedis::Data
- Defined in:
- lib/multi_redis/data.rb
Instance Attribute Summary collapse
-
#contents ⇒ Object
readonly
Returns the value of attribute contents.
Instance Method Summary collapse
- #[](k) ⇒ Object
- #[]=(k, v) ⇒ Object
-
#initialize ⇒ Data
constructor
A new instance of Data.
- #method_missing(symbol, *args, &block) ⇒ Object
Constructor Details
#initialize ⇒ Data
Returns a new instance of Data.
7 8 9 |
# File 'lib/multi_redis/data.rb', line 7 def initialize @contents = Hash.new end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(symbol, *args, &block) ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/multi_redis/data.rb', line 19 def method_missing symbol, *args, &block if @contents.key? symbol @contents[symbol] elsif m = symbol.to_s.match(/\A(.*)\=\Z/) raise "Reserved name" if respond_to? acc = m[1].to_sym @contents[acc] = args[0] else super symbol, *args, &block end end |
Instance Attribute Details
#contents ⇒ Object (readonly)
Returns the value of attribute contents.
5 6 7 |
# File 'lib/multi_redis/data.rb', line 5 def contents @contents end |
Instance Method Details
#[](k) ⇒ Object
11 12 13 |
# File 'lib/multi_redis/data.rb', line 11 def [] k @contents[k] end |
#[]=(k, v) ⇒ Object
15 16 17 |
# File 'lib/multi_redis/data.rb', line 15 def []= k, v @contents[k.to_sym] = v end |