Class: Hash

Inherits:
Object
  • Object
show all
Defined in:
lib/bloggit/etc/hash.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object

Extends a hash so that it can be used like an object in a template context (e.g. hash.key)



4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/bloggit/etc/hash.rb', line 4

def method_missing(name, *args)
  if name.to_s.ends_with? '='
    name = name.to_s[0..-2]
    self[name] = args[0]
  else
    if self.has_key? name.to_s
      self[name.to_s]
    elsif self.has_key? name.to_sym
      self[name.to_sym]
    else
      super(name,*args)
    end
  end
end

Instance Method Details

#get_bindingObject

Returns the binding so you can retrieve values from it…



20
21
22
# File 'lib/bloggit/etc/hash.rb', line 20

def get_binding
  binding
end