From: Dave Thomas Date: 2000-12-23T03:24:26+09:00 Subject: [ruby-talk:7973] Re: Hash access method Ted Meng writes: > I wonder if the ruby 1.8 could allow "." access > to Hash object. such as > > h = {'a' => 1} > h.a # 1 > h.a = 2 > h.a # 2 What happens if the key is an instance method of hash? h = {'clear' => a, 'foggy' => 2 } h.clear # ? However, ignoring this small issue, you can implement something similar for yourself: class Hash def method_missing(m, *args) name = m.to_s if name[-1] == ?= self[name[0..-2]] = args[0] else self.fetch(name) end end end h = { "a" => 1, "b" => 2 } h.a #=> 1 h.b #=> 2 h.a = 99 h.a #=> 99 h #=> {"a"=>99, "b"=>2} I love this language! Dave