From 85b8c9ace1296d6ae5e20a34a691d34c96bf6dee Mon Sep 17 00:00:00 2001 From: Sunny Ripert Date: Mon, 12 Jan 2026 20:25:45 +0100 Subject: [PATCH 1/3] Lint: Fix Performance/StringIdentifierArgument --- .rubocop.yml | 1 + .rubocop_todo.yml | 13 +++++++++++++ Gemfile | 1 + spec/money/rates_store/memory_spec.rb | 2 +- 4 files changed, 16 insertions(+), 1 deletion(-) diff --git a/.rubocop.yml b/.rubocop.yml index 8b5a17f71f..1e307d7184 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,6 +1,7 @@ inherit_from: .rubocop_todo.yml plugins: + - rubocop-performance - rubocop-rake - rubocop-rspec diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index bd6fee5e59..e43b85c8b7 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -30,6 +30,19 @@ Metrics/ModuleLength: Metrics/PerceivedComplexity: Max: 16 +# This cop supports unsafe autocorrection (--autocorrect-all). +# Configuration parameters: OnlySumOrWithInitialValue. +Performance/Sum: + Exclude: + - 'spec/money/allocation_spec.rb' + - 'spec/money_spec.rb' + +# This cop supports unsafe autocorrection (--autocorrect-all). +Performance/TimesMap: + Exclude: + - 'spec/currency_spec.rb' + - 'spec/money_spec.rb' + # Configuration parameters: CountAsOne. RSpec/ExampleLength: Max: 38 diff --git a/Gemfile b/Gemfile index 36d9253e5f..5ecf555c7f 100644 --- a/Gemfile +++ b/Gemfile @@ -20,6 +20,7 @@ gem "rake" # Linting gem "rubocop", require: false +gem "rubocop-performance", require: false gem "rubocop-rake", require: false gem "rubocop-rspec", require: false diff --git a/spec/money/rates_store/memory_spec.rb b/spec/money/rates_store/memory_spec.rb index 3b0b6d98d2..abd98bf902 100644 --- a/spec/money/rates_store/memory_spec.rb +++ b/spec/money/rates_store/memory_spec.rb @@ -42,7 +42,7 @@ end describe "#transaction" do - let(:guard) { store.instance_variable_get("@guard") } + let(:guard) { store.instance_variable_get(:@guard) } before do allow(guard).to receive(:synchronize) From 0a678366994c33e0054c77e5299d8d80c6a50231 Mon Sep 17 00:00:00 2001 From: Sunny Ripert Date: Mon, 12 Jan 2026 20:28:21 +0100 Subject: [PATCH 2/3] Lint: Fix Performance/TimesMap --- .rubocop_todo.yml | 6 ------ spec/money/currency_spec.rb | 2 +- spec/money_spec.rb | 2 +- 3 files changed, 2 insertions(+), 8 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index e43b85c8b7..9473e6b432 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -37,12 +37,6 @@ Performance/Sum: - 'spec/money/allocation_spec.rb' - 'spec/money_spec.rb' -# This cop supports unsafe autocorrection (--autocorrect-all). -Performance/TimesMap: - Exclude: - - 'spec/currency_spec.rb' - - 'spec/money_spec.rb' - # Configuration parameters: CountAsOne. RSpec/ExampleLength: Max: 38 diff --git a/spec/money/currency_spec.rb b/spec/money/currency_spec.rb index 04da83328d..6252fc2b91 100644 --- a/spec/money/currency_spec.rb +++ b/spec/money/currency_spec.rb @@ -310,7 +310,7 @@ def to_s it "is thread safe" do ids = [] - 2.times.map { Thread.new { ids << described_class.new("USD").object_id } }.each(&:join) + Array.new(2) { Thread.new { ids << described_class.new("USD").object_id } }.each(&:join) expect(ids.uniq.length).to eq(1) end end diff --git a/spec/money_spec.rb b/spec/money_spec.rb index c079d702e4..2280148349 100644 --- a/spec/money_spec.rb +++ b/spec/money_spec.rb @@ -889,7 +889,7 @@ end it "does not round rationals" do - splits = 7.times.map { Rational(950, 6650) } + splits = Array.new(7) { Rational(950, 6650) } moneys = Money.us_dollar(6650).allocate(splits) moneys.each do |money| expect(money.cents).to eq 950 From 9ee6385f2da6045d5e7a6f2310345afa14538d2d Mon Sep 17 00:00:00 2001 From: Sunny Ripert Date: Mon, 12 Jan 2026 20:30:35 +0100 Subject: [PATCH 3/3] Lint: Fix Performance/Sum --- .rubocop_todo.yml | 7 ------- spec/money/allocation_spec.rb | 10 +++++----- spec/money_spec.rb | 4 ++-- 3 files changed, 7 insertions(+), 14 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 9473e6b432..bd6fee5e59 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -30,13 +30,6 @@ Metrics/ModuleLength: Metrics/PerceivedComplexity: Max: 16 -# This cop supports unsafe autocorrection (--autocorrect-all). -# Configuration parameters: OnlySumOrWithInitialValue. -Performance/Sum: - Exclude: - - 'spec/money/allocation_spec.rb' - - 'spec/money_spec.rb' - # Configuration parameters: CountAsOne. RSpec/ExampleLength: Max: 38 diff --git a/spec/money/allocation_spec.rb b/spec/money/allocation_spec.rb index eda4ca54c6..264a27ced0 100644 --- a/spec/money/allocation_spec.rb +++ b/spec/money/allocation_spec.rb @@ -56,7 +56,7 @@ BigDecimal("33.3333333333"), ], ) - expect(parts.inject(0, :+)).to eq(amount) + expect(parts.sum).to eq(amount) end end end @@ -132,7 +132,7 @@ BigDecimal("33.3333333333"), ], ) - expect(parts.inject(0, :+)).to eq(amount) + expect(parts.sum).to eq(amount) end end end @@ -156,7 +156,7 @@ ] result = described_class.generate(amount, allocations) - expect(result.reduce(&:+)).to eq(amount) + expect(result.sum).to eq(amount) expect(result).to eq( [ 61566, @@ -193,7 +193,7 @@ ] result = described_class.generate(amount, allocations) - expect(result.reduce(&:+)).to eq(amount) + expect(result.sum).to eq(amount) expect(result).to eq( [ -61566, @@ -229,7 +229,7 @@ it "allocates with required precision" do result = described_class.generate(amount, allocations, 16) - expect(result.reduce(&:+)).to eq(amount) + expect(result.sum).to eq(amount) expected = %w[ 6.3347130857200688 6.3347130857200689 6.3347130857200688 6.3347130857200688 diff --git a/spec/money_spec.rb b/spec/money_spec.rb index 2280148349..02dc61f293 100644 --- a/spec/money_spec.rb +++ b/spec/money_spec.rb @@ -937,7 +937,7 @@ context "with infinite_precision", :default_infinite_precision_true do it "allows for fractional cents allocation" do moneys = Money.new(100).allocate([1, 1, 1]) - expect(moneys.inject(0, :+)).to eq(Money.new(100)) + expect(moneys.sum).to eq(Money.new(100)) end end end @@ -975,7 +975,7 @@ context "with infinite_precision", :default_infinite_precision_true do it "allows for splitting by fractional cents" do moneys = Money.new(100).split(3) - expect(moneys.inject(0, :+)).to eq(Money.new(100)) + expect(moneys.sum).to eq(Money.new(100)) end end end