From: Tomas Matousek Date: 2010-04-10T03:45:02+09:00 Subject: [ruby-core:29396] Invalid names --_000_4B342496A3EFEB48839E10BB4BF5964C49296E71TK5EX14MBXC124r_ Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable I wonder what your opinions are on using invalid method names in define_met= hod. Ruby allows it today and some frameworks (e.g. shoulda) depend on it. On the other hand some frameworks depend on method names returned by method= s, instance_methods, etc. being correct method names. The pattern methods.e= ach { |m| eval("def #{m}(...) ...") } is used quite frequently. Methods that define other members - instance variables (instance_variable_s= et), class variables (class_variable_set), constants (const_set) - don't ac= cept invalid names. A NameError is raised. Shouldn't define_method also raise NameError if the argument is not a valid= method name and the code that depends on this behavior be fixed? Or, if co= nsidered useful, shouldn't arbitrary names be allowed for constants, instan= ce variables and class variables as well? Tomas --_000_4B342496A3EFEB48839E10BB4BF5964C49296E71TK5EX14MBXC124r_ Content-Type: text/html; charset="us-ascii" Content-Transfer-Encoding: quoted-printable

I wonder what yo= ur opinions are on using invalid method names in define_method. =

 

Ruby all= ows it today and some frameworks (e.g. shoulda) depend on it.

On the other hand some frameworks depend on method n= ames returned by methods, instance_methods, etc. being correct method names= . The pattern methods.each { |m| eval(“def #{m}(…) …̶= 1;) } is used quite frequently.

&n= bsp;

Methods that define other members - inst= ance variables (instance_variable_set), class variables (class_variable_set= ), constants (const_set) - don’t accept invalid names. A NameError is= raised.

Shouldn’t define_method = also raise NameError if the argument is not a valid method name and the cod= e that depends on this behavior be fixed? Or, if considered useful, shouldn= ’t arbitrary names be allowed for constants, instance variables and c= lass variables as well?

 

Tomas

= --_000_4B342496A3EFEB48839E10BB4BF5964C49296E71TK5EX14MBXC124r_--