Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 05bb5ac

Browse files
committed
Support endless ranges as the final argument to a when clause.
1 parent bf8e3b1 commit 05bb5ac

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
1010

1111
- Support for Ruby 3.1 syntax, including: blocks without names, hash keys without values, endless methods without parentheses, and new argument forwarding.
1212
- Support for pinned expressions and variables within pattern matching.
13+
- Support endless ranges as the final argument to a `when` clause.
1314

1415
## [1.1.1] - 2021-12-09
1516

lib/syntax_tree.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13246,6 +13246,14 @@ def format(q)
1324613246
separator = -> { q.group { q.comma_breakable } }
1324713247
q.seplist(arguments.parts, separator) { |part| q.format(part) }
1324813248
end
13249+
13250+
# Very special case here. If you're inside of a when clause and the
13251+
# last argument to the predicate is and endless range, then you are
13252+
# forced to use the "then" keyword to make it parse properly.
13253+
last = arguments.parts.last
13254+
if (last.is_a?(Dot2) || last.is_a?(Dot3)) && !last.right
13255+
q.text(" then")
13256+
end
1324913257
end
1325013258
end
1325113259

test/fixtures/when.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,11 @@
4646
when foo
4747
else
4848
end
49+
%
50+
case
51+
when foo.. then
52+
end
53+
%
54+
case
55+
when foo... then
56+
end

0 commit comments

Comments
 (0)