From: "Ara.T.Howard" Date: 2005-07-29T04:41:01+09:00 Subject: Re: Method Scope (again b/c google groups lost it) On Fri, 29 Jul 2005, Trans wrote: > I would like to see Ruby gain a "scoping feature" (I usually refer to > this as a "namespace", but looking at Matz' discussion of Rite he's > using that to mean something else). This idea is this: > > class String > > scope format > > def jumble > ... > end > > end > > end > > "Wizard".format.jumble harp:~ > cat a.rb class Dispatch < Hash def method_missing(m, *a, &b); self[m].call(*a, &b); end end class String def format(*a, &b) Dispatch[ :jumble => lambda{ 'jumble' }, :bumble => lambda{ 'bumble' }, ] end end p "Wizard".format.jumble p "Wizard".format.bumble harp:~ > ruby a.rb "jumble" "bumble" easy cheasy. ;-) -a -- =============================================================================== | email :: ara [dot] t [dot] howard [at] noaa [dot] gov | phone :: 303.497.6469 | My religion is very simple. My religion is kindness. | --Tenzin Gyatso ===============================================================================