Actions
Bug #20637
closedSyntaxError class definition in method body can be bypassed
Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 3.4.0dev (2024-07-11T06:59:45Z master a1f7432550) [x86_64-linux]
Description
Class definition in method body is prohibited in Ruby
def f
class ::A; end # class definition in method body (SyntaxError)
module B; end # module definition in method body (SyntaxError)
end
But it can be bypassed by using class <<
def f
class << Object.new
class ::A; end # Syntax OK
module B; end # Syntax OK
end
end
Actions
Like0
Like0Like0Like0Like0