class RuboCop::Cop::Performance::OpenStruct
end
end
MyStruct.new(‘my_value1’, ‘my_value2’)
def my_method
MyStruct = Struct.new(:my_key1, :my_key2)
class MyClass
# good
end
end
OpenStruct.new(my_key1: ‘my_value1’, my_key2: ‘my_value2’)
def my_method
class MyClass
# bad
@example
are not equivalent.
This cop is unsafe because ‘OpenStruct.new` and `Struct.new`
@safety
applications with multiple `OpenStruct` instantiations.
especially in case of single-threaded
This could have an effect on performance,
definition during program runtime.
Ruby global method cache as it causes dynamic method
Instantiation of an `OpenStruct` invalidates
Checks for `OpenStruct.new` calls.
def on_send(node)
def on_send(node) open_struct(node) do add_offense(node.loc.selector) end end