Project

General

Profile

Actions

Bug #11983

closed

define_method not raising error for invalid method name

Bug #11983: define_method not raising error for invalid method name

Added by anilmaurya (Anil Maurya) almost 10 years ago. Updated almost 10 years ago.

Status:
Rejected
Assignee:
-
Target version:
-
[ruby-core:72829]

Description

Steps to Reproduce:

Inside irb:

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

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.

Actions

Also available in: PDF Atom