Skip to content

Commit 875a09e

Browse files
committed
Prefer literal -> lambdas over Kernel#lambda
* I'll take care of fixing the style for new specs.
1 parent 7cd019f commit 875a09e

File tree

1,226 files changed

+4968
-4953
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,226 files changed

+4968
-4953
lines changed

.rubocop.yml

+15
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,18 @@ Lint/UriRegexp:
100100
Lint/Debugger:
101101
Exclude:
102102
- 'core/binding/fixtures/irb.rb'
103+
104+
Style/Lambda:
105+
Enabled: true
106+
EnforcedStyle: literal
107+
Exclude:
108+
- 'language/lambda_spec.rb'
109+
- 'language/proc_spec.rb'
110+
- 'core/kernel/lambda_spec.rb'
111+
112+
Style/EmptyLambdaParameter:
113+
Enabled: true
114+
115+
Style/StabbyLambdaParentheses:
116+
Enabled: true
117+
EnforcedStyle: require_no_parentheses

core/argf/close_spec.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222

2323
it "doesn't raise an IOError if called on a closed stream" do
2424
argf [@file1_name] do
25-
lambda { @argf.close }.should_not raise_error
26-
lambda { @argf.close }.should_not raise_error
25+
-> { @argf.close }.should_not raise_error
26+
-> { @argf.close }.should_not raise_error
2727
end
2828
end
2929
end

core/argf/read_nonblock_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464

6565
it 'raises IO::EAGAINWaitReadable when empty' do
6666
argf ['-'] do
67-
lambda {
67+
-> {
6868
@argf.read_nonblock(4)
6969
}.should raise_error(IO::EAGAINWaitReadable)
7070
end

core/argf/readchar_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
it "raises EOFError when end of stream reached" do
1515
argf [@file1, @file2] do
16-
lambda { while @argf.readchar; end }.should raise_error(EOFError)
16+
-> { while @argf.readchar; end }.should raise_error(EOFError)
1717
end
1818
end
1919
end

core/argf/readline_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
it "raises an EOFError when reaching end of files" do
1919
argf [@file1, @file2] do
20-
lambda { while @argf.readline; end }.should raise_error(EOFError)
20+
-> { while @argf.readline; end }.should raise_error(EOFError)
2121
end
2222
end
2323
end

core/argf/readpartial_spec.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
it "raises an ArgumentError if called without a maximum read length" do
1818
argf [@file1_name] do
19-
lambda { @argf.readpartial }.should raise_error(ArgumentError)
19+
-> { @argf.readpartial }.should raise_error(ArgumentError)
2020
end
2121
end
2222

@@ -59,8 +59,8 @@
5959
@argf.readpartial(@file1.size)
6060
@argf.readpartial(1)
6161
@argf.readpartial(@file2.size)
62-
lambda { @argf.readpartial(1) }.should raise_error(EOFError)
63-
lambda { @argf.readpartial(1) }.should raise_error(EOFError)
62+
-> { @argf.readpartial(1) }.should raise_error(EOFError)
63+
-> { @argf.readpartial(1) }.should raise_error(EOFError)
6464
end
6565
end
6666

core/argf/rewind_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
it "raises an ArgumentError when end of stream reached" do
3434
argf [@file1_name, @file2_name] do
3535
@argf.read
36-
lambda { @argf.rewind }.should raise_error(ArgumentError)
36+
-> { @argf.rewind }.should raise_error(ArgumentError)
3737
end
3838
end
3939
end

core/argf/seek_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757

5858
it "takes at least one argument (offset)" do
5959
argf [@file1_name] do
60-
lambda { @argf.seek }.should raise_error(ArgumentError)
60+
-> { @argf.seek }.should raise_error(ArgumentError)
6161
end
6262
end
6363
end

core/argf/shared/eof.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
it "raises IOError when called on a closed stream" do
1919
argf [@file1] do
2020
@argf.read
21-
lambda { @argf.send(@method) }.should raise_error(IOError)
21+
-> { @argf.send(@method) }.should raise_error(IOError)
2222
end
2323
end
2424
end

core/argf/shared/fileno.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
it "raises an ArgumentError when called on a closed stream" do
1919
argf [@file1] do
2020
@argf.read
21-
lambda { @argf.send(@method) }.should raise_error(ArgumentError)
21+
-> { @argf.send(@method) }.should raise_error(ArgumentError)
2222
end
2323
end
2424
end

core/argf/shared/pos.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
it "raises an ArgumentError when called on a closed stream" do
2626
argf [@file1] do
2727
@argf.read
28-
lambda { @argf.send(@method) }.should raise_error(ArgumentError)
28+
-> { @argf.send(@method) }.should raise_error(ArgumentError)
2929
end
3030
end
3131
end

core/argf/skip_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,6 @@
3737
# which as a side-effect calls argf.file which will initialize
3838
# internals of ARGF enough for this to work.
3939
it "has no effect when nothing has been processed yet" do
40-
lambda { ARGF.class.new(@file1_name).skip }.should_not raise_error
40+
-> { ARGF.class.new(@file1_name).skip }.should_not raise_error
4141
end
4242
end

core/array/allocate_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@
1414
end
1515

1616
it "does not accept any arguments" do
17-
lambda { Array.allocate(1) }.should raise_error(ArgumentError)
17+
-> { Array.allocate(1) }.should raise_error(ArgumentError)
1818
end
1919
end

core/array/append_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
end
3232

3333
it "raises a #{frozen_error_class} on a frozen array" do
34-
lambda { ArraySpecs.frozen_array << 5 }.should raise_error(frozen_error_class)
34+
-> { ArraySpecs.frozen_array << 5 }.should raise_error(frozen_error_class)
3535
end
3636
end
3737

core/array/at_spec.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@
4747
end
4848

4949
it "raises a TypeError when the passed argument can't be coerced to Integer" do
50-
lambda { [].at("cat") }.should raise_error(TypeError)
50+
-> { [].at("cat") }.should raise_error(TypeError)
5151
end
5252

5353
it "raises an ArgumentError when 2 or more arguments are passed" do
54-
lambda { [:a, :b].at(0,1) }.should raise_error(ArgumentError)
54+
-> { [:a, :b].at(0,1) }.should raise_error(ArgumentError)
5555
end
5656
end

core/array/bsearch_index_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
end
2222

2323
it "raises a TypeError when block returns a String" do
24-
lambda { [1, 2, 3].bsearch_index { "not ok" } }.should raise_error(TypeError)
24+
-> { [1, 2, 3].bsearch_index { "not ok" } }.should raise_error(TypeError)
2525
end
2626

2727
it "returns nil when block is empty" do

core/array/bsearch_spec.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99
it_behaves_like :enumeratorized_with_unknown_size, :bsearch, [1,2,3]
1010

1111
it "raises a TypeError if the block returns an Object" do
12-
lambda { [1].bsearch { Object.new } }.should raise_error(TypeError)
12+
-> { [1].bsearch { Object.new } }.should raise_error(TypeError)
1313
end
1414

1515
it "raises a TypeError if the block returns a String" do
16-
lambda { [1].bsearch { "1" } }.should raise_error(TypeError)
16+
-> { [1].bsearch { "1" } }.should raise_error(TypeError)
1717
end
1818

1919
context "with a block returning true or false" do

core/array/clear_spec.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
end
3030

3131
it "does not accept any arguments" do
32-
lambda { [1].clear(true) }.should raise_error(ArgumentError)
32+
-> { [1].clear(true) }.should raise_error(ArgumentError)
3333
end
3434

3535
it "keeps untrusted status" do
@@ -43,6 +43,6 @@
4343
it "raises a #{frozen_error_class} on a frozen array" do
4444
a = [1]
4545
a.freeze
46-
lambda { a.clear }.should raise_error(frozen_error_class)
46+
-> { a.clear }.should raise_error(frozen_error_class)
4747
end
4848
end

core/array/compact_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,6 @@
7272
end
7373

7474
it "raises a #{frozen_error_class} on a frozen array" do
75-
lambda { ArraySpecs.frozen_array.compact! }.should raise_error(frozen_error_class)
75+
-> { ArraySpecs.frozen_array.compact! }.should raise_error(frozen_error_class)
7676
end
7777
end

core/array/concat_spec.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@
3333
end
3434

3535
it "raises a #{frozen_error_class} when Array is frozen and modification occurs" do
36-
lambda { ArraySpecs.frozen_array.concat [1] }.should raise_error(frozen_error_class)
36+
-> { ArraySpecs.frozen_array.concat [1] }.should raise_error(frozen_error_class)
3737
end
3838

3939
# see [ruby-core:23666]
4040
it "raises a #{frozen_error_class} when Array is frozen and no modification occurs" do
41-
lambda { ArraySpecs.frozen_array.concat([]) }.should raise_error(frozen_error_class)
41+
-> { ArraySpecs.frozen_array.concat([]) }.should raise_error(frozen_error_class)
4242
end
4343

4444
it "keeps tainted status" do

core/array/cycle_spec.rb

+8-8
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
ScratchPad.record []
77

88
@array = [1, 2, 3]
9-
@prc = lambda { |x| ScratchPad << x }
9+
@prc = -> x { ScratchPad << x }
1010
end
1111

1212
it "does not yield and returns nil when the array is empty and passed value is an integer" do
@@ -46,13 +46,13 @@
4646
end
4747

4848
it "does not rescue StopIteration when not passed a count" do
49-
lambda do
49+
-> do
5050
@array.cycle { raise StopIteration }
5151
end.should raise_error(StopIteration)
5252
end
5353

5454
it "does not rescue StopIteration when passed a count" do
55-
lambda do
55+
-> do
5656
@array.cycle(3) { raise StopIteration }
5757
end.should raise_error(StopIteration)
5858
end
@@ -74,23 +74,23 @@
7474
count = mock("cycle count 2")
7575
count.should_receive(:to_int).and_return("2")
7676

77-
lambda { @array.cycle(count, &@prc) }.should raise_error(TypeError)
77+
-> { @array.cycle(count, &@prc) }.should raise_error(TypeError)
7878
end
7979

8080
it "raises a TypeError if passed a String" do
81-
lambda { @array.cycle("4") { } }.should raise_error(TypeError)
81+
-> { @array.cycle("4") { } }.should raise_error(TypeError)
8282
end
8383

8484
it "raises a TypeError if passed an Object" do
85-
lambda { @array.cycle(mock("cycle count")) { } }.should raise_error(TypeError)
85+
-> { @array.cycle(mock("cycle count")) { } }.should raise_error(TypeError)
8686
end
8787

8888
it "raises a TypeError if passed true" do
89-
lambda { @array.cycle(true) { } }.should raise_error(TypeError)
89+
-> { @array.cycle(true) { } }.should raise_error(TypeError)
9090
end
9191

9292
it "raises a TypeError if passed false" do
93-
lambda { @array.cycle(false) { } }.should raise_error(TypeError)
93+
-> { @array.cycle(false) { } }.should raise_error(TypeError)
9494
end
9595

9696
before :all do

core/array/delete_at_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
end
3737

3838
it "raises a #{frozen_error_class} on a frozen array" do
39-
lambda { [1,2,3].freeze.delete_at(0) }.should raise_error(frozen_error_class)
39+
-> { [1,2,3].freeze.delete_at(0) }.should raise_error(frozen_error_class)
4040
end
4141

4242
it "keeps tainted status" do

core/array/delete_if_spec.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@
4040
end
4141

4242
it "raises a #{frozen_error_class} on a frozen array" do
43-
lambda { ArraySpecs.frozen_array.delete_if {} }.should raise_error(frozen_error_class)
43+
-> { ArraySpecs.frozen_array.delete_if {} }.should raise_error(frozen_error_class)
4444
end
4545

4646
it "raises a #{frozen_error_class} on an empty frozen array" do
47-
lambda { ArraySpecs.empty_frozen_array.delete_if {} }.should raise_error(frozen_error_class)
47+
-> { ArraySpecs.empty_frozen_array.delete_if {} }.should raise_error(frozen_error_class)
4848
end
4949

5050
it "keeps tainted status" do

core/array/delete_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def x.==(other) 3 == other end
4141
end
4242

4343
it "raises a #{frozen_error_class} on a frozen array" do
44-
lambda { [1, 2, 3].freeze.delete(1) }.should raise_error(frozen_error_class)
44+
-> { [1, 2, 3].freeze.delete(1) }.should raise_error(frozen_error_class)
4545
end
4646

4747
it "keeps tainted status" do

core/array/dig_spec.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,20 @@
2020
end
2121

2222
it "raises a TypeError for a non-numeric index" do
23-
lambda {
23+
-> {
2424
['a'].dig(:first)
2525
}.should raise_error(TypeError)
2626
end
2727

2828
it "raises a TypeError if any intermediate step does not respond to #dig" do
2929
a = [1, 2]
30-
lambda {
30+
-> {
3131
a.dig(0, 1)
3232
}.should raise_error(TypeError)
3333
end
3434

3535
it "raises an ArgumentError if no arguments provided" do
36-
lambda {
36+
-> {
3737
[10].dig()
3838
}.should raise_error(ArgumentError)
3939
end

core/array/drop_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
end
77

88
it "raises an ArgumentError if the number of elements specified is negative" do
9-
lambda { [1, 2].drop(-3) }.should raise_error(ArgumentError)
9+
-> { [1, 2].drop(-3) }.should raise_error(ArgumentError)
1010
end
1111

1212
it "returns an empty Array if all elements are dropped" do

0 commit comments

Comments
 (0)