Skip to content

Commit

Permalink
Implement Range#inspect for beginless ranges
Browse files Browse the repository at this point in the history
Co-authored-by: Nicolas Laurent norswap@gmail.com
  • Loading branch information
Lillian Zhang authored and Nicolas Laurent committed Nov 30, 2020
1 parent 16205c7 commit 692b604
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/main/ruby/truffleruby/core/range.rb
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,14 @@ def ===(value)
end

def inspect
"#{self.begin.inspect}#{exclude_end? ? "..." : ".."}#{Truffle::RangeOperations.endless?(self) ? "" : self.end.inspect}"
sep = exclude_end? ? '...' : '..'
if (Primitive.nil?(self.begin) && Primitive.nil?(self.end))
result = "nil#{sep}nil"
else
result = (Primitive.nil?(self.begin) ? '' : self.begin.inspect) + sep +
(Primitive.nil?(self.end) ? '' : self.end.inspect)
end
Primitive.infect(result, self)
end

def last(n=undefined)
Expand Down

0 comments on commit 692b604

Please sign in to comment.