From: "tompng (tomoya ishida) via ruby-core" Date: 2024-07-16T12:38:34+00:00 Subject: [ruby-core:118618] [Ruby master Bug#20637] SyntaxError class definition in method body can be bypassed 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/ ______________________________________________ ruby-core mailing list -- ruby-core@ml.ruby-lang.org To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/