Hi,
I think I probably was somewhat unclear in my other post. I wasn't
arguing for or against your idea (for the most part), I was going off
it and thinking up a related idea... I guess it was actually pretty
off topic.
Well, then you'll learn that your instance must implement to_int. Same as
if someone had coded that directly in the method. I don't see this as an
argument against my suggested shortcut syntax, because that mainly affects
the *writer* of a method - not the *caller*.
My only argument against the shortcut syntax is that I can't see how
often it could be used, except to simulate static typing. I suspect
that adding a feature like this would encourage the use of static
typing in methods.
In your example method, you called #to_int on an object that you were
just going to call #times on. This doesn't guarantee that you will get
an integer, and makes it difficult for others to use duck typing in
code that interfaces with yours. In fact, if they need the
functionality, then the have to resort to some hack like this:
obj = ObjectThatImplementsTimes.new
wrapper = Object.new
class << wrapper;self;end.__send__
define_method, :to_int){obj}
A very ugly hack, just to re-allow duck typing.
You introduced the #respond_to? - my suggestion was to simply invoke it and
see what happens (duck typing).
I was describing something else; I was describing a possible problem
with *my* implementation of a related idea. OT, I know :/
Sure. I'm very open here. I think the selection of "." as separator was
not good. We can change that any time. But the real issue for me is, does
this make sense independend of syntax?
I still think that this is, for the most part, an implementation of
static typing. It may just be me, but I very rarely use to_str,
to_int, etc, in my code. The only time I do is when I absolutely have
to have those particular classes. Which is so uncommon for me, I can't
think of the last time I used it. But as I said, I may very well be in
the minority here.
cheers,
Mark