T
Trans
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
Currently I can implement like so:
require 'delegate'
class String
def format
@__format__ ||= Format.new( self )
end
class Format < DelegateClass( self )
def jumble
...
end
end
end
But that has a whole lot of icky overhead. I would be nice if Ruby
could support this kind of thing natively. It's a nice way to organize
methods.
T.
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
Currently I can implement like so:
require 'delegate'
class String
def format
@__format__ ||= Format.new( self )
end
class Format < DelegateClass( self )
def jumble
...
end
end
end
But that has a whole lot of icky overhead. I would be nice if Ruby
could support this kind of thing natively. It's a nice way to organize
methods.
T.