posts in category * ruby

Object Like Hash

4.28.2013

"My crime is that of curiosity"

While I was going through the source code of camping this piece of code that gives you Object like Hash got my attention. Instead of using Hash['key'] it allows you to use Hash.key hence the name "Object Like Hash".

Code

class H < Hash
    def method_missing(m,*a)
          m.to_s=~/=$/?self[$`]=a[0]:a==[]?self[m.to_s]:super
      end

      undef id, type if ?? == 63
  end

Usage

read more