Class: Hash

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

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args) ⇒ Object

Access a hash as a JavaScript hash: foo.bar.baz Gavin Kistner – blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/92897



4
5
6
7
8
9
10
# File 'lib/core_ext/hash.rb', line 4

def method_missing(meth,*args)
  if /=$/=~(meth=meth.id2name) then
    self[meth[0...-1]] = (args.length<2 ? args[0] : args)
  else
    self[meth]
  end
end