Skip to content

Commit a154f4b

Browse files
committed
Revert "Reapply "[Feature #6012] Extend source_location for end position"
This reverts commit 8f5e0d8ff82ff63d60da445826fa44be3d8d0820.
1 parent 63ffa64 commit a154f4b

3 files changed

Lines changed: 30 additions & 55 deletions

File tree

core/method/source_location_spec.rb

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,23 @@
1111
end
1212

1313
it "sets the first value to the path of the file in which the method was defined" do
14-
file = @method.source_location[0]
14+
file = @method.source_location.first
1515
file.should be_an_instance_of(String)
1616
file.should == File.realpath('fixtures/classes.rb', __dir__)
1717
end
1818

1919
it "sets the last value to an Integer representing the line on which the method was defined" do
20-
line = @method.source_location[1]
20+
line = @method.source_location.last
2121
line.should be_an_instance_of(Integer)
2222
line.should == 5
2323
end
2424

2525
it "returns the last place the method was defined" do
26-
MethodSpecs::SourceLocation.method(:redefined).source_location[1].should == 13
26+
MethodSpecs::SourceLocation.method(:redefined).source_location.last.should == 13
2727
end
2828

2929
it "returns the location of the original method even if it was aliased" do
30-
MethodSpecs::SourceLocation.new.method(:aka).source_location[1].should == 17
30+
MethodSpecs::SourceLocation.new.method(:aka).source_location.last.should == 17
3131
end
3232

3333
it "works for methods defined with a block" do
@@ -108,13 +108,7 @@ def f
108108
c = Class.new do
109109
eval('def self.m; end', nil, "foo", 100)
110110
end
111-
location = c.method(:m).source_location
112-
ruby_version_is(""..."4.0") do
113-
location.should == ["foo", 100]
114-
end
115-
ruby_version_is("4.0") do
116-
location.should == ["foo", 100, 0, 100, 15]
117-
end
111+
c.method(:m).source_location.should == ["foo", 100]
118112
end
119113

120114
describe "for a Method generated by respond_to_missing?" do

core/proc/source_location_spec.rb

Lines changed: 19 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -17,64 +17,57 @@
1717
end
1818

1919
it "sets the first value to the path of the file in which the proc was defined" do
20-
file = @proc.source_location[0]
20+
file = @proc.source_location.first
2121
file.should be_an_instance_of(String)
2222
file.should == File.realpath('fixtures/source_location.rb', __dir__)
2323

24-
file = @proc_new.source_location[0]
24+
file = @proc_new.source_location.first
2525
file.should be_an_instance_of(String)
2626
file.should == File.realpath('fixtures/source_location.rb', __dir__)
2727

28-
file = @lambda.source_location[0]
28+
file = @lambda.source_location.first
2929
file.should be_an_instance_of(String)
3030
file.should == File.realpath('fixtures/source_location.rb', __dir__)
3131

32-
file = @method.source_location[0]
32+
file = @method.source_location.first
3333
file.should be_an_instance_of(String)
3434
file.should == File.realpath('fixtures/source_location.rb', __dir__)
3535
end
3636

37-
it "sets the second value to an Integer representing the line on which the proc was defined" do
38-
line = @proc.source_location[1]
37+
it "sets the last value to an Integer representing the line on which the proc was defined" do
38+
line = @proc.source_location.last
3939
line.should be_an_instance_of(Integer)
4040
line.should == 4
4141

42-
line = @proc_new.source_location[1]
42+
line = @proc_new.source_location.last
4343
line.should be_an_instance_of(Integer)
4444
line.should == 12
4545

46-
line = @lambda.source_location[1]
46+
line = @lambda.source_location.last
4747
line.should be_an_instance_of(Integer)
4848
line.should == 8
4949

50-
line = @method.source_location[1]
50+
line = @method.source_location.last
5151
line.should be_an_instance_of(Integer)
5252
line.should == 15
5353
end
5454

5555
it "works even if the proc was created on the same line" do
56-
ruby_version_is(""..."4.0") do
57-
proc { true }.source_location.should == [__FILE__, __LINE__]
58-
Proc.new { true }.source_location.should == [__FILE__, __LINE__]
59-
-> { true }.source_location.should == [__FILE__, __LINE__]
60-
end
61-
ruby_version_is("4.0") do
62-
proc { true }.source_location.should == [__FILE__, __LINE__, 11, __LINE__, 19]
63-
Proc.new { true }.source_location.should == [__FILE__, __LINE__, 15, __LINE__, 23]
64-
-> { true }.source_location.should == [__FILE__, __LINE__, 6, __LINE__, 17]
65-
end
56+
proc { true }.source_location.should == [__FILE__, __LINE__]
57+
Proc.new { true }.source_location.should == [__FILE__, __LINE__]
58+
-> { true }.source_location.should == [__FILE__, __LINE__]
6659
end
6760

6861
it "returns the first line of a multi-line proc (i.e. the line containing 'proc do')" do
69-
ProcSpecs::SourceLocation.my_multiline_proc.source_location[1].should == 20
70-
ProcSpecs::SourceLocation.my_multiline_proc_new.source_location[1].should == 34
71-
ProcSpecs::SourceLocation.my_multiline_lambda.source_location[1].should == 27
62+
ProcSpecs::SourceLocation.my_multiline_proc.source_location.last.should == 20
63+
ProcSpecs::SourceLocation.my_multiline_proc_new.source_location.last.should == 34
64+
ProcSpecs::SourceLocation.my_multiline_lambda.source_location.last.should == 27
7265
end
7366

7467
it "returns the location of the proc's body; not necessarily the proc itself" do
75-
ProcSpecs::SourceLocation.my_detached_proc.source_location[1].should == 41
76-
ProcSpecs::SourceLocation.my_detached_proc_new.source_location[1].should == 51
77-
ProcSpecs::SourceLocation.my_detached_lambda.source_location[1].should == 46
68+
ProcSpecs::SourceLocation.my_detached_proc.source_location.last.should == 41
69+
ProcSpecs::SourceLocation.my_detached_proc_new.source_location.last.should == 51
70+
ProcSpecs::SourceLocation.my_detached_lambda.source_location.last.should == 46
7871
end
7972

8073
it "returns the same value for a proc-ified method as the method reports" do
@@ -93,12 +86,6 @@
9386

9487
it "works for eval with a given line" do
9588
proc = eval('-> {}', nil, "foo", 100)
96-
location = proc.source_location
97-
ruby_version_is(""..."4.0") do
98-
location.should == ["foo", 100]
99-
end
100-
ruby_version_is("4.0") do
101-
location.should == ["foo", 100, 0, 100, 5]
102-
end
89+
proc.source_location.should == ["foo", 100]
10390
end
10491
end

core/unboundmethod/source_location_spec.rb

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,23 @@
77
end
88

99
it "sets the first value to the path of the file in which the method was defined" do
10-
file = @method.source_location[0]
10+
file = @method.source_location.first
1111
file.should be_an_instance_of(String)
1212
file.should == File.realpath('fixtures/classes.rb', __dir__)
1313
end
1414

15-
it "sets the second value to an Integer representing the line on which the method was defined" do
16-
line = @method.source_location[1]
15+
it "sets the last value to an Integer representing the line on which the method was defined" do
16+
line = @method.source_location.last
1717
line.should be_an_instance_of(Integer)
1818
line.should == 5
1919
end
2020

2121
it "returns the last place the method was defined" do
22-
UnboundMethodSpecs::SourceLocation.method(:redefined).unbind.source_location[1].should == 13
22+
UnboundMethodSpecs::SourceLocation.method(:redefined).unbind.source_location.last.should == 13
2323
end
2424

2525
it "returns the location of the original method even if it was aliased" do
26-
UnboundMethodSpecs::SourceLocation.instance_method(:aka).source_location[1].should == 17
26+
UnboundMethodSpecs::SourceLocation.instance_method(:aka).source_location.last.should == 17
2727
end
2828

2929
it "works for define_method methods" do
@@ -54,12 +54,6 @@
5454
c = Class.new do
5555
eval('def m; end', nil, "foo", 100)
5656
end
57-
location = c.instance_method(:m).source_location
58-
ruby_version_is(""..."4.0") do
59-
location.should == ["foo", 100]
60-
end
61-
ruby_version_is("4.0") do
62-
location.should == ["foo", 100, 0, 100, 10]
63-
end
57+
c.instance_method(:m).source_location.should == ["foo", 100]
6458
end
6559
end

0 commit comments

Comments
 (0)