Class: RuboCop::Cop::Performance::OpenStruct
| Relationships & Source Files | |
| Super Chains via Extension / Inclusion / Inheritance | |
|
Class Chain:
self,
Base
|
|
|
Instance Chain:
self,
Base
|
|
| Inherits: |
Base
|
| 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
-
MSG =
# File 'lib/rubocop/cop/performance/open_struct.rb', line 35'Consider using `Struct` over `OpenStruct` to optimize the performance.' -
RESTRICT_ON_SEND =
# File 'lib/rubocop/cop/performance/open_struct.rb', line 36%i[new].freeze
Instance Method Summary
Instance Method Details
#on_send(node)
[ GitHub ]# 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