Class: OrderedHashWithIndifferentAccess

Inherits:
BSON::OrderedHash
  • Object
show all
Defined in:
lib/cubicle/ordered_hash_with_indifferent_access.rb

Direct Known Subclasses

Cubicle::Data::Level

Instance Method Summary collapse

Constructor Details

#initialize(initial_data = {}) ⇒ OrderedHashWithIndifferentAccess

Returns a new instance of OrderedHashWithIndifferentAccess.



2
3
4
# File 'lib/cubicle/ordered_hash_with_indifferent_access.rb', line 2

def initialize(initial_data={})
  merge!(initial_data.stringify_keys)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *args, &block) ⇒ Object



21
22
23
24
25
# File 'lib/cubicle/ordered_hash_with_indifferent_access.rb', line 21

def method_missing(sym,*args,&block)
  return self[sym.to_s[0..-2]] = args[0] if sym.to_s =~ /.*=$/
  return self[sym] if include?(sym)
  nil
end

Instance Method Details

#[](key) ⇒ Object



7
8
9
10
11
# File 'lib/cubicle/ordered_hash_with_indifferent_access.rb', line 7

def [](key)
  key = key.to_s
  #self[key] = [] unless self.keys.include?(key)
  super(key)
end

#[]=(key, val) ⇒ Object



13
14
15
# File 'lib/cubicle/ordered_hash_with_indifferent_access.rb', line 13

def []=(key,val)
  super(key.to_s,val)
end

#include?(key) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/cubicle/ordered_hash_with_indifferent_access.rb', line 17

def include?(key)
  super(key.to_s)
end