Class: RuboCop::Cop::Performance::OpenStruct
- Inherits:
-
Base
- Object
- Base
- RuboCop::Cop::Performance::OpenStruct
- Defined in:
- lib/rubocop/cop/performance/open_struct.rb
Overview
Checks for ‘OpenStruct.new` calls. Instantiation of an `OpenStruct` invalidates Ruby global method cache as it causes dynamic method definition during program runtime. This could have an effect on performance, especially in case of single-threaded applications with multiple `OpenStruct` instantiations.
Constant Summary collapse
- MSG =
'Consider using `Struct` over `OpenStruct` to optimize the performance.'
- RESTRICT_ON_SEND =
%i[new].freeze
Instance Method Summary collapse
Instance Method Details
#on_send(node) ⇒ Object
42 43 44 45 46 |
# File 'lib/rubocop/cop/performance/open_struct.rb', line 42 def on_send(node) open_struct(node) do add_offense(node.loc.selector) end end |