From: ko1@... Date: 2019-01-30T12:24:36+00:00 Subject: [ruby-core:91341] [Ruby trunk Feature#15575] Prohibit to pass a block singleton class Issue #15575 has been updated by ko1 (Koichi Sasada). Eregon (Benoit Daloze) wrote: > Agreed. > IMHO `class << expr` should be no different than the normal `class Name`, but currently various things are allowed in that context such as `return`, `yield`, etc. > > Constant resolution also becomes somewhat dynamically-scoped with `class << expr` which is also a weird exception. > So longer term maybe it would be good to deprecate `class <<` entirely and use `singleton_class.class_exec do` instead. or make it syntax sugre of `singleton_class.class_exec do`? Both are easy to explain the rule. Now, it is somewhat unclear. ---------------------------------------- Feature #15575: Prohibit to pass a block singleton class https://bugs.ruby-lang.org/issues/15575#change-76590 * Author: ko1 (Koichi Sasada) * Status: Open * Priority: Normal * Assignee: matz (Yukihiro Matsumoto) * Target version: ---------------------------------------- The following code works now: ``` def foo class << Object.new yield end end foo{ p :ok } #=> :ok ``` but I think this feature is very strange because local variables are not active in singleton class. How about to prohibit this feature? plan: warning at ruby 2.7 and prohibit it in ruby 3. -- https://bugs.ruby-lang.org/ Unsubscribe: