DottedIndex mixin: extend a Hash or Array class with this module to achieve [] and []= methods that automatically split indices at dots (indices are automatically converted to symbols, too)
You have to define the single_retrieve(key) and single_assign(key,value) methods (usually aliased at the original :[] and :[]= methods)
# File lib/rbot/core/utils/extends.rb, line 55 def [](*ar) keys = self.rbot_index_split(ar) return self.single_retrieve(keys.first) if keys.length == 1 h = self while keys.length > 1 k = keys.shift h[k] ||= self.class.new h = h[k] end h[keys.last] end
# File lib/rbot/core/utils/extends.rb, line 67 def []=(*arr) val = arr.last ar = arr[0..-2] keys = self.rbot_index_split(ar) return self.single_assign(keys.first, val) if keys.length == 1 h = self while keys.length > 1 k = keys.shift h[k] ||= self.class.new h = h[k] end h[keys.last] = val end
Generated with the Darkfish Rdoc Generator 2.