-
Notifications
You must be signed in to change notification settings - Fork 21.9k
Closed
Description
Steps to reproduce
delegate
with option private: true
seems not compatible with the method_added
hook.
In the following snippet, delegate
creates a private method #foo
. However the method_added
hook is called BEFORE the delegate
code changes its visibility to false
.
class MyTestClass
def foo = "foo"
end
class MyClass
attr_reader :my_test_class
def initialize(my_test_class)
@my_test_class = my_test_class
end
def self.method_added(method_name)
puts "#{method_name} is public: #{public_method_defined?(method_name, true)}"
# super(method_name)
end
delegate :foo, to: :my_test_class, private: true
end
The source code of delegate
shows that: we always define a method as public first, then change its visibility. But the method_added
hook is executed between these 2 steps.
Is it possible to take into account the method visibility when defining a method? Thanks
Expected behavior
When loading MyClass
, the output is foo is public: false
Actual behavior
When loading MyClass
, the output is foo is public: true
System configuration
Rails version: 7.0.4.3
Ruby version: 3.2.2
Metadata
Metadata
Assignees
Labels
No labels