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
# # this is not redundant because `delegate` creates methods
# private
#
# delegate :method_a, to: :method_b
# end
This says that the Rails method delegate respects access modifiers, however that doesn't seem to be the case:
require"active_support/core_ext/module/delegation"require"ostruct"classBardefquxOpenStruct.new(baz: "bar")endendclassFoo < Barprivatedelegate:baz,to: :qux# private: true is what you'd wantendputsFoo.new.baz# works just fine
MethodCreatingMethods is for things like define_method that are aware of their current visibility. A somewhat contrived example would be:
classCprivate# wrongly flagged as Lint/UselessAccessModifier: Useless private access modifiersend:define_method,:foo,->{'E621'}# `private` is respected when `foo` is definedendC.new.foo# private method `foo' called for #<C:0x00007fa1770405b8> (NoMethodError)
rubocop/lib/rubocop/cop/lint/useless_access_modifier.rb
Lines 114 to 126 in b4080d8
This says that the Rails method
delegate
respects access modifiers, however that doesn't seem to be the case:This is further supported by
delegate
having a keyword argument calledprivate
to achieve the desired behaviour: https://api.rubyonrails.org/classes/Module.html#method-i-delegateI would change docs myself but can't actually think of a usecase for this config value.
The text was updated successfully, but these errors were encountered: