Redefine "method" method

  • Thread starter Iñaki Baz Castillo
  • Start date
I

Iñaki Baz Castillo

Hi, I'd like to have a method called "method" in some classes, but=20
since "method" is a Ruby method present in any class I would like if it cou=
ld=20
originate any problem.

=2D-=20
I=C3=B1aki Baz Castillo
 
T

Tommy Morgan

Technically, it seems that you could do something along the lines of the
following:

class Test
class << self
undef_method "method"
end
end

Although... that really seems like a bad idea. I don't know enough about th=
e
internals to say whether or not anything would break (I poked at it a littl=
e
and haven't tripped across any side effects, but it seems like there should
be).

Any chance you could just use a different name for your method?

--Tommy M.
 
I

Iñaki Baz Castillo

El Mi=C3=A9rcoles, 13 de Agosto de 2008, Tommy Morgan escribi=C3=B3:
Any chance you could just use a different name for your method?

Of course, but I'm doing a SIP protocol application, in which a core concep=
t=20
is the *method* (INVITE, ACK, BYE...), so it would be really nice to use:

request.method

instead of:

request.sip_method <--- This is what I use for now.

Thanks.

=2D-=20
I=C3=B1aki Baz Castillo
 
R

Robert Klemme

Hi, I'd like to have a method called "method" in some classes, but
since "method" is a Ruby method present in any class I would like if itcould
originate any problem.

I'd say the idea is not so good because - depending on libraries that
you use - you might experience errors or strange behavior. I'd rather
choose a different name if at all possible.

Kind regards

robert
 
I

Iñaki Baz Castillo

El Mi=E9rcoles, 13 de Agosto de 2008, Robert Klemme escribi=F3:
I'd say the idea is not so good because - depending on libraries that
you use - you might experience errors or strange behavior. I'd rather
choose a different name if at all possible.

Thanks.
In fact, I've just realized that I can use "Method" nada :)


=2D-=20
I=F1aki Baz Castillo
 
T

Tommy Morgan

Well, for what it's wirth:

I think request.sip_method is actually better.
While it's important to try and go for naming conventions in your code that
are succinct, you also want to avoid ambiguity. If someone else is looking
at your code and they see 'request.method', it isn't obvious that you are
referring to something aside from what is built into ruby. sip_method helps
to avoid that ambiguity, and it also allows you to go back and utilize the
built-in method if you need to at some point in the future.

Hope that helps.

--Tommy M.
 
I

Iñaki Baz Castillo

El Mi=C3=A9rcoles, 13 de Agosto de 2008, Tommy Morgan escribi=C3=B3:
Well, for what it's wirth:

I think request.sip_method is actually better.
While it's important to try and go for naming conventions in your code th= at
are succinct, you also want to avoid ambiguity. If someone else is looking
at your code and they see 'request.method', it isn't obvious that you are
referring to something aside from what is built into ruby. sip_method hel= ps
to avoid that ambiguity, and it also allows you to go back and utilize the
built-in method if you need to at some point in the future.

Hope that helps.

Enough arguments to remain using "sip_method" :)

Thanks.

=2D-=20
I=C3=B1aki Baz Castillo
 

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,995
Messages
2,570,231
Members
46,820
Latest member
GilbertoA5

Latest Threads

Top