Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

define_method allowing any name?

0 views
Skip to first unread message

gabriele renzi

unread,
Aug 24, 2005, 6:22:13 AM8/24/05
to
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.

>> class C
>> define_method " ^_^ " do "happy!" end
>> end
=> #<Proc:0x02988088@(irb):6>
>> C.new.send " ^_^ "
=> "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 :)

Trans

unread,
Aug 24, 2005, 7:18:05 AM8/24/05
to
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.

gabriele renzi

unread,
Aug 24, 2005, 10:26:00 AM8/24/05
to
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 :)

0 new messages