You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The following code dynamically creates a class using Class.new:
class NestedMethods
def definer
Class.new do
def foo
'foo'
end
end
end
end
and rubocop (0.36.0 (using Parser 2.3.0.1, running on ruby 2.2.0 x86_64-darwin14)) reports that foo is nested:
foo.rb:4:7: W: Method definitions must not be nested. Use lambda instead.
def foo
^^^^^^^
However, these method definitions are not nested, since Class.new has changed the internal klass pointer and foo is defined on the new class rather than NestedMethods. Furthermore, as the docs say: If a block is given, it is passed the class object, and the block is evaluated in the context of this class using class_eval., therefore I believe the nested method warning should treat Class.new in the same way as class_eval and instance_eval, namely, not issuing a nested method definition warning.
The text was updated successfully, but these errors were encountered:
The following code dynamically creates a class using
Class.new
:and rubocop (
0.36.0 (using Parser 2.3.0.1, running on ruby 2.2.0 x86_64-darwin14)
) reports thatfoo
is nested:However, these method definitions are not nested, since
Class.new
has changed the internalklass
pointer andfoo
is defined on the new class rather thanNestedMethods
. Furthermore, as the docs say:If a block is given, it is passed the class object, and the block is evaluated in the context of this class using class_eval.
, therefore I believe the nested method warning should treatClass.new
in the same way asclass_eval
andinstance_eval
, namely, not issuing a nested method definition warning.The text was updated successfully, but these errors were encountered: