Project

General

Profile

Actions

Bug #20637

open

SyntaxError class definition in method body can be bypassed

Added by tompng (tomoya ishida) 1 day ago. Updated 1 day ago.

Status:
Open
Assignee:
-
Target version:
-
ruby -v:
ruby 3.4.0dev (2024-07-11T06:59:45Z master a1f7432550) [x86_64-linux]
[ruby-core:118616]

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

Also available in: Atom PDF

Like0
Like0Like0