Ryan Davis wrote:
> ...There are times when
> I just want one method that does a number of different but related
> things...
I gotta say wrt your original motivation, to me the need for this
"feature" reeks of bad design. Even ignoring Eric's appeal for
readability/separation of tokens, wanting a single method that "does
a
number of different but related things" says to me that
maintainability
and comprehensibility is going to be sacrificed in the medium-to-long
run.
It encourages cramming another handler into an existing method when
writing a new method is the appropriate thing to do. Documentation?
Unit testing??? Gah.
Not necessarily. First off, if one takes this too its ends, one has a
whole lot more clutter in method name space. Moreover, there are a
number of methods that very only by a few variations.
For instance
File.new:ro( filename )
vs.
File.new( filname, FILE::READONLY )
or larger
File.new:creat:trunc:rdwr("newfile", 0644)
vs.
File.new("newfile", File::CREAT|File::TRUNC|File::RDWR, 0644)
And parsability??
You are asking the parser to differentiate var.method:arg.method
between var.method(:arg).method and var.method(:arg.method) based on
(I'm guessing) the context of already being within a method call.
No, just on whether there's a space or not. Is there a third valid
interpetation that would make this impossible?
You'll break _all_ existing code that reads var.method arg.method.
? That should run jut as it does now as 'var.method(arg.method)'. You
must be trying to point out something else?
I don't see how, given the original example and the followups, the
benefits outweigh the costs.
Perhaps. It's just something that I have come across as a possibility.
At the moment I am preferring the use of an intermediary method, a
"methobox" in effect.
class String
def format
Format.new( self )
end
class Format
def self ; word ; end
def initialize( word )
@self = word
end
def jossle
r = ''
@self.each_char{ |c| r << ( c[0] % 2 == 0 ? c.upcase :
c.downcase ) }
r
end
end
end
"apple".format.jossle #=> aPpLe
In my mind, this sure beats the pants off of messing with modules and
keeps the namespace nice and clean and organized. Futher more, lower
routines that are considered more common can be "aliased" upward.
class String
def jossle
format.jossle
end
end
T
···
On Jan 31, 2005, at 6:40 PM, Trans wrote: