class RubbyCop::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/rubbycop/cop/performance/fixed_size.rb, line 14
def on_send(node)
  return if allowed_parent?(node.parent)

  counter(node) do |var, arg|
    return if allowed_variable?(var) || allowed_argument?(arg)

    add_offense(node, :expression)
  end
end

Private Instance Methods

allowed_argument?(arg) click to toggle source
# File lib/rubbycop/cop/performance/fixed_size.rb, line 30
def allowed_argument?(arg)
  arg && non_string_argument?(arg.first)
end
allowed_parent?(node) click to toggle source
# File lib/rubbycop/cop/performance/fixed_size.rb, line 34
def allowed_parent?(node)
  node && (node.casgn_type? || node.block_type?)
end
allowed_variable?(var) click to toggle source
# File lib/rubbycop/cop/performance/fixed_size.rb, line 26
def allowed_variable?(var)
  contains_splat?(var) || contains_double_splat?(var)
end
contains_double_splat?(node) click to toggle source
# File lib/rubbycop/cop/performance/fixed_size.rb, line 44
def contains_double_splat?(node)
  return unless node.hash_type?

  node.each_child_node(:kwsplat).any?
end
contains_splat?(node) click to toggle source
# File lib/rubbycop/cop/performance/fixed_size.rb, line 38
def contains_splat?(node)
  return unless node.array_type?

  node.each_child_node(:splat).any?
end
non_string_argument?(node) click to toggle source
# File lib/rubbycop/cop/performance/fixed_size.rb, line 50
def non_string_argument?(node)
  node && !node.str_type?
end