Is overloading of the "! operator" possible or not

  • Thread starter Neulinger Robert \(SMS T CARS SW External\)
  • Start date
N

Neulinger Robert \(SMS T CARS SW External\)

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/rubyfaq-7.html
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
 
Y

Yukihiro Matsumoto

Hi

In message "Re: Is overloading of the "! operator" possible or not"

|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.
 
S

Stephan Kämper

Neulinger said:
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/rubyfaq-7.html
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
 
F

Florian Gross

Stephan said:
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.
 
B

Bertram Scharpf

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/rubyfaq-7.html
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.html#operator)
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
 
B

Bertram Scharpf

Hi Zach,

Am Dienstag, 25. Jan 2005, 01:49:51 +0900 schrieb Zach Dennis:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,164
Messages
2,570,898
Members
47,440
Latest member
YoungBorel

Latest Threads

Top