From: Aaron Patterson Date: 2009-10-13T01:34:12+09:00 Subject: Re: Subclassing in module from top module? On Oct 12, 2009, at 9:20 AM, Vít Ondruch wrote: > Hello everybody, > > I would like to have locally monkeypatched Hash in my module. I would > expect that following example will work, however it doesn't. How to do > it correctly? "local" and "monkeypatch" don't go together. You can have a subclass though. > irb(main):016:0> module Foo > irb(main):017:1> class Hash << ::Hash > irb(main):018:2> def bar > irb(main):019:3> puts 'bar' > irb(main):020:3> end > irb(main):021:2> end > irb(main):022:1> end > SyntaxError: (irb):17: syntax error, unexpected tLSHFT, expecting > '<' or > ';' or '\n' > class Hash << ::Hash > ^ > from c:/Ruby/bin/irb:12:in `
' Use one "<" to subclass Hash: module Foo class Hash < ::Hash ... end end --- Aaron Patterson http://tenderlovemaking.com