[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Is overloading of the "! operator" possible or not

Neulinger Robert \(SMS T CARS SW External\)

1/24/2005 8:15:00 AM

Hello,

I'm tying to overload the "! operator", which should be possible due
to the explanation in the book "Programming ruby" -> The Ruby
Language ->Operator Expressions,
but it's not working.

On the other hand in the FAQ the ! operator is marked as non-overloadable.
---------------
http://www.rubycentral.com/faq/ruby...
See section 7.2...
However, the following are built-in control structures, not methods, which
cannot be overridden.

=,


--------------


What is the truth and/or how does it work?

Thanks for help in advance Robert


6 Answers

Yukihiro Matsumoto

1/24/2005 8:42:00 AM

0

Hi

In message "Re: Is overloading of the "! operator" possible or not"
on Mon, 24 Jan 2005 17:25:52 +0900, "Neulinger Robert (SMS T CARS SW External)" <Neulinger.External@infineon.com> writes:

|I'm tying to overload the "! operator", which should be possible due
|to the explanation in the book "Programming ruby" -> The Ruby
|Language ->Operator Expressions,
|but it's not working.

No, you can't.

matz.


Stephan Kämper

1/24/2005 11:14:00 AM

0

Neulinger Robert (SMS T CARS SW External) wrote:
> Hello,
>
> I'm tying to overload the "! operator", which should be possible due

Do you mean "overload" or "override"?
You _override_ a method if you change the behaviour of the method in an
ancestor (or singleton object).

To _overload_ a method means to check the classes/types of the arguments
and to use that information to decide which method body to execute.
Overloading just doesn't cut the mustard in Ruby; IIRC this has been
discussed here before.

> to the explanation in the book "Programming ruby" -> The Ruby
> Language ->Operator Expressions,
> but it's not working.
>
> On the other hand in the FAQ the ! operator is marked as non-overloadable.
> ---------------
> http://www.rubycentral.com/faq/ruby...
> See section 7.2...
> However, the following are built-in control structures, not methods, which
> cannot be overridden.
>
> What is the truth and/or how does it work?
>
> Thanks for help in advance Robert

That should be "override", not "overload" in the FAQ.
As I understand the table in the pickaxe (2nd ed. PDF instance, p. 324):

tick-mark ! ~ + - Not,complement, unary plus and minus
(method names for the last two are +@ and
-@)

indicates that all these operations may be overridden. Which indeed work
for '~', '+' and '-', but not for '!'.

At least this is how I understand what Matz posted and what the FAQ
states. (The operator group in the pickaxe should probably be split up.)

Furthermore I'll go and suggest another 'Q' for the FAQ: A discussion
about the difference of overriding and overloading in Ruby.

Happy rubying

Stephan

Florian Gross

1/24/2005 1:14:00 PM

0

Stephan Kämper wrote:

> Do you mean "overload" or "override"?
> You _override_ a method if you change the behaviour of the method in an
> ancestor (or singleton object).
>
> To _overload_ a method means to check the classes/types of the arguments
> and to use that information to decide which method body to execute.
> Overloading just doesn't cut the mustard in Ruby; IIRC this has been
> discussed here before.

IMHO these terms are equivalent in Ruby. What the C++ / Java guys
usually call overloading is typically called Multi Method Dispatch in
more dynamic languages.

Bertram Scharpf

1/24/2005 4:46:00 PM

0

Hi,

Am Montag, 24. Jan 2005, 17:25:52 +0900 schrieb Neulinger Robert (SMS T CARS SW External):
> I'm tying to overload the "! operator", which should be possible due
> to the explanation in the book "Programming ruby" -> The Ruby
> Language ->Operator Expressions,
> but it's not working.
>
> On the other hand in the FAQ the ! operator is marked as non-overloadable.
> ---------------
> http://www.rubycentral.com/faq/ruby...
> See section 7.2...
>
> What is the truth and/or how does it work?

Further, the 1.4 Manual
(http://www.ruby-doc.org/docs/Manual/man-1.4/syntax.htm...)
says:

Most of operators are just method invocation in special
form. But some operators are not methods, but built in to
the syntax:

=, .., ..., !, not, &&, and, ||, or, !=, !~

Bertram



--
Bertram Scharpf
Stuttgart, Deutschland/Germany
http://www.bertram-...


Zach Dennis

1/24/2005 4:50:00 PM

0

Bertram Scharpf wrote:

>
> Further, the 1.4 Manual
> (http://www.ruby-doc.org/docs/Manual/man-1.4/syntax.htm...)
> says:

All I had to say is wow. Could I have you on my research/debugging team?

Zach


Bertram Scharpf

1/24/2005 9:12:00 PM

0

Hi Zach,

Am Dienstag, 25. Jan 2005, 01:49:51 +0900 schrieb Zach Dennis:
> Bertram Scharpf wrote:
> >
> >Further, the 1.4 Manual
> >(http://www.ruby-doc.org/docs/Manual/man-1.4/syntax.htm...)
> >says:
>
> All I had to say is wow. Could I have you on my research/debugging team?

I would like to. But first I have to process the dozens and
dozens of emails on my HTTP (ruby-talk/125379) and backquote
(ruby-core/4273) problems.

Bertram

--
Bertram Scharpf
Stuttgart, Deutschland/Germany
http://www.bertram-...