Methods names mangled with number of arguments

M

Mystifier

------=_NextPart_000_0064_01C504CA.B67C9510
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: quoted-printable

Hi
=20
The current situation in Ruby with method calls is=20
=20
class A
def meth(arg1)
end
end
=20
class B < A
def meth(arg1,arg2)
end
end
=20
a =3D A.new
b =3D B.new
=20
b.meth(1,2) is fine but a.meth(1,2) . This is fine but what one assumes =
is
that when a method is overridden, you wish to override the =
implementation.
In that case, this is a problem.
=20
My suggestion is 2 options.
=20
Option 1:
Make all the methods as variable arguments. If a method is get more
arguments then it uses, it can safely ignore the extra ones. In case it =
gets
lesser ones (I am not sure here) , it may take the values as nil.
I do not think this is a good option but messaging based languages like =
Ruby
might prefer them.
=20
Option 2:
Mangle method names with number of arguments. meth in class A becomes =
meth_1
and meth in class B becomes meth_2. So, B is not actually overriding the
meth.
=20
regards,
Mystifier
=20
http://vuby.berlios.de
=20
=20
=20

------=_NextPart_000_0064_01C504CA.B67C9510--
 
G

Gavin Kistner

The current situation in Ruby with method calls is

class A
def meth(arg1)
end
end

class B < A
def meth(arg1,arg2)
end
end

a = A.new
b = B.new

b.meth(1,2) is fine but a.meth(1,2) . This is fine but what one
assumes is
that when a method is overridden, you wish to override the
implementation.
In that case, this is a problem.

If you wish to override the implementation, then you should do so:

class A
def meth(arg1)
end
end

#...later...
class A
def meth(arg1,arg2)
end
end


It would not make sense to affect/change a parent class that you
inherit from. Consider:

class Animal
def eat
gobble_ravenously()
end
end

class Person < Animal
def eat
use_fork_and_knife()
end
end

If the 'redefinition' of #eat by the Person class affected the Animal
class, all animals would suddenly be using cutlery.

Am I misunderstanding you?
 

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
473,968
Messages
2,570,154
Members
46,702
Latest member
LukasConde

Latest Threads

Top