define_method allowing any name?

G

gabriele renzi

Hi gurus and rubys,

I can't remeber if this was discussed in the past,
but I just noticed that it's possible to define
a method with an invalid name bypassing the syntactic
check via define_method, i.e.
=> "happy!"

(works in 1.8, untested on cvs HEAD)

I think this behaviour should be prohibited
(but on the other hand it opens great possibilities :)
 
T

Trans

What's wrong with that behavior? I think its good to have.
Unfortunately there's not a whole lot to do with it except to "hide"
methods. I'd like to see this:

C.new."^_^"

That could be helpful for DSLs. This would allow for a much closer E4X
implementation for instance.

xml."@attribute"

T.
 
G

gabriele renzi

Trans ha scritto:
What's wrong with that behavior? I think its good to have.

I think methods-which-do-the-same-as-some-syntax[1] should behave
accordingly to that.

Say, delegate.rb uses #eval to define methods.
The Evil Eval could probably be replaced with define_method,
but the behaviour could be different since #eval locks out invalid
methods with a SyntaxError, while define_method accepts them.
Unfortunately there's not a whole lot to do with it except to "hide"
methods. I'd like to see this:

C.new."^_^"

That could be helpful for DSLs. This would allow for a much closer E4X
implementation for instance.

xml."@attribute"

well, I think most reasonable DSLs should use proper words not
punctuation, but I'd appreciate an Emoticon Specific Language :)


[1] I mean #eval, Class#new, Module#new,define_method etc.. sorry, can't
think of a better name :)
 

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

No members online now.

Forum statistics

Threads
474,176
Messages
2,570,950
Members
47,503
Latest member
supremedee

Latest Threads

Top