Skip to content

Commit 1df210d

Browse files
committed
Print beginless ranges properly
Instead of displaying the start of the range as nil
1 parent 6e086e6 commit 1df210d

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

lib/pp.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ def pretty_print_cycle(q) # :nodoc:
442442

443443
class Range # :nodoc:
444444
def pretty_print(q) # :nodoc:
445-
q.pp self.begin
445+
q.pp self.begin if self.begin
446446
q.breakable ''
447447
q.text(self.exclude_end? ? '...' : '..')
448448
q.breakable ''

test/test_pp.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@ def o.method
2828
end
2929
assert_equal(%(""\n), PP.pp(o, "".dup))
3030
end
31+
32+
def test_range
33+
assert_equal("0..1\n", PP.pp(0..1, "".dup))
34+
assert_equal("0...1\n", PP.pp(0...1, "".dup))
35+
assert_equal("0...\n", PP.pp(0..., "".dup))
36+
assert_equal("...1\n", PP.pp(...1, "".dup))
37+
end
3138
end
3239

3340
class HasInspect

0 commit comments

Comments
 (0)