class RuboCop::Cop::Performance::FixedSize
Do not compute the size of statically sized objects.
Constants
- MSG
Public Instance Methods
on_send(node)
click to toggle source
# File lib/rubocop/cop/performance/fixed_size.rb, line 14 def on_send(node) counter(node) do |variable, arg| return if contains_splat?(variable) return if contains_double_splat?(variable) return if !arg.nil? && string_argument?(arg.first) if node.parent return if node.parent.casgn_type? || node.parent.block_type? end add_offense(node, :expression) end end
Private Instance Methods
contains_double_splat?(node)
click to toggle source
# File lib/rubocop/cop/performance/fixed_size.rb, line 37 def contains_double_splat?(node) return unless node.hash_type? node.children.any? do |child| child.respond_to?(:kwsplat_type?) && child.kwsplat_type? end end
contains_splat?(node)
click to toggle source
# File lib/rubocop/cop/performance/fixed_size.rb, line 29 def contains_splat?(node) return unless node.array_type? node.children.any? do |child| child.respond_to?(:splat_type?) && child.splat_type? end end
string_argument?(node)
click to toggle source
# File lib/rubocop/cop/performance/fixed_size.rb, line 45 def string_argument?(node) node && !node.str_type? end