[ruby-core:72830] [Ruby trunk - Bug #11983] [Rejected] define_method not raising error for invalid method name

From: nobu@...
Date: 2016-01-12 15:26:32 UTC
List: ruby-core #72830
Issue #11983 has been updated by Nobuyoshi Nakada.

Description updated
Status changed from Open to Rejected

It's a spec that `define_method` can define any name and `__send__` also can call it.

----------------------------------------
Bug #11983: define_method not raising error for invalid method name
https://bugs.ruby-lang.org/issues/11983#change-56069

* Author: Anil Maurya
* Status: Rejected
* Priority: Normal
* Assignee: 
* ruby -v: 
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN, 2.3: UNKNOWN
----------------------------------------
## Steps to Reproduce:

Inside irb:

~~~ruby
Class A
end

A.send(:define_method, "may_run!?") do |*args, &block|
  p "random text"
end

a = A.new

a.may_run!?
~~~

* never return from this function.

-----------------------------------------------

IF I try to declare this function using `class_eval`

~~~ruby
A.class_eval <<-EQRUBY
  def may_run!?
    p 'some text'
  end
EQRUBY
end
~~~

I got error: `syntax error, unexpected '?', expecting ';' or '\n'`.

I think `class_eval` behaviour is right because `may_run!?` is invalid name for method and `define_method` should raise error instead of defining it.




-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>

In This Thread

Prev Next