From: Hal Fulton Date: 2003-09-11T07:15:18+09:00 Subject: Re: ANN: MetaTags 1.0 Chad Fowler wrote: > On Thu, 11 Sep 2003, Austin Ziegler wrote: > > # On Thu, 11 Sep 2003 04:05:26 +0900, Ben Giddings wrote: > # > Richard Kilmer wrote: > # >> Then: > # >> class String > # >> def &(klass) > # >> klass.from_str(self) > # >> end > # >> end > # >> then you can do: > # >> c = "one hump or two" & Caml > # > I like this better than Dave's suggestion of the Caml() function, but it > # > is somewhat confusing. Since the "&" is already used, I thought maybe > # > another operator might make more sense, but I discovered that there is > # > only a small set of operators that seem to be overloadable. Is there a > # > complete list somewhere of overloadable operators? > # > # irb(main):001:0> "a" & "b" > # NoMethodError: undefined method `&' for "a":String > # from (irb):1 > # irb(main):002:0> VERSION > # => "1.8.0" > # > > Did you miss the part that said > > class String > def &(klass) > ....etc. > > ? I think he was responding to the part that said, "Since & is already used..." To play mediator and clear up any confusion (if I can get my attributions straight!): Someone defined an & operator. Rich wanted something other than &. I *think* Ben thought that Rich was saying the String#& was already defined; so he tried to correct him You (Chad) thought that Ben had failed to see the definition of String#& Now in (partial) answer to the question of what's overloadable: 1. You can only overload genuine operators/methods; not assignment, not dot, not ::, etc. I can't remember the full list. 2. You can never overload something that is not already recognized by the parser as an operator -- e.g. you can't create your own operators using arbitrary punctation as in (I think) SNOBOL. Cheers, Hal