Class: RuboCop::Cop::Performance::BigDecimalWithNumericArgument
Relationships & Source Files | |
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
self,
AutoCorrector,
Base
|
|
Instance Chain:
self,
Base
|
|
Inherits: |
Base
|
Defined in: | lib/rubocop/cop/performance/big_decimal_with_numeric_argument.rb |
Overview
Identifies places where numeric argument to BigDecimal should be converted to string. Initializing from String is faster than from Numeric for BigDecimal.
Constant Summary
-
MSG =
# File 'lib/rubocop/cop/performance/big_decimal_with_numeric_argument.rb', line 26'Convert numeric literal to string and pass it to `BigDecimal`.'
-
RESTRICT_ON_SEND =
# File 'lib/rubocop/cop/performance/big_decimal_with_numeric_argument.rb', line 27%i[BigDecimal to_d].freeze
Instance Method Summary
Instance Method Details
#on_send(node)
[ GitHub ]# File 'lib/rubocop/cop/performance/big_decimal_with_numeric_argument.rb', line 37
def on_send(node) if (numeric = big_decimal_with_numeric_argument?(node)) add_offense(numeric.source_range) do |corrector| corrector.wrap(numeric, "'", "'") end elsif (numeric_to_d = to_d?(node)) add_offense(numeric_to_d.source_range) do |corrector| big_decimal_args = node.arguments.map(&:source).unshift("'#{numeric_to_d.source}'").join(', ') corrector.replace(node, "BigDecimal(#{big_decimal_args})") end end end