
Issue #20637 has been updated by tompng (tomoya ishida). dynamic constant assignment (SyntaxError) can be also bypassed ~~~ruby def f class << Object.new ::A = 1 end end ~~~ ---------------------------------------- Bug #20637: SyntaxError class definition in method body can be bypassed https://bugs.ruby-lang.org/issues/20637#change-109146 * Author: tompng (tomoya ishida) * Status: Open * ruby -v: ruby 3.4.0dev (2024-07-11T06:59:45Z master a1f7432550) [x86_64-linux] * Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN ---------------------------------------- Class definition in method body is prohibited in Ruby ~~~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 <<` ~~~ruby def f class << Object.new class ::A; end # Syntax OK module B; end # Syntax OK end end ~~~ -- https://bugs.ruby-lang.org/