Actions
Bug #12696
closedDefining anonymous classes via `Class.new {}` does not run `class_eval` on the block
Description
When defining anonymous classes, the documentation comment (https://github.com/ruby/ruby/blob/b9a82eaa13a5438318d78aee0afb907a1d143a51/object.c#L1754) explains that
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.
However, it seems that class_eval
is never run.
If it was, then both of the examples below would have the same printed output, but they do not.
class Class
alias_method :old_class_eval, :class_eval
def class_eval(*args, &block)
puts '1. foo'
old_class_eval *args, &block
puts '3. bar'
end
end
# Example 1
some_class = Class.new do
puts '2. baz'
end
# Example 2
other_class = Class.new
other_class.class_eval { puts '2. baz' }
I'm not sure if the documentation is misleading me or if i should be able to hook into class_eval
but can't.
Actions
Like0
Like0