From: daniel@... Date: 2018-06-11T09:49:41+00:00 Subject: [ruby-core:87470] [Ruby trunk Feature#7580] Range translation Issue #7580 has been updated by DanielRHeath (Daniel Heath). Duplicated at https://bugs.ruby-lang.org/issues/14777 Agree that '+' seems an idiomatic name (I'm using ranges to represent coordinate ranges for bounding boxes). It's somewhat awkward given that a Range can be eg ('a'..'z') - should `('a'..'z') + 'b'` return `('ab'..'zb')`? ---------------------------------------- Feature #7580: Range translation https://bugs.ruby-lang.org/issues/7580#change-72463 * Author: charliesome (Charlie Somerville) * Status: Assigned * Priority: Normal * Assignee: matz (Yukihiro Matsumoto) * Target version: ---------------------------------------- =begin I would like to propose the (({#+})) and (({#-})) methods on (({Range})). These would be useful for translating ranges - for example, given a range where the endpoints are 1-indexed, the range could be translated by 1 in the negative direction to use in (({Array#[]})). Instead of doing a syntactically-bulky manual translation like so: ary[(range.begin - 1)..(range.end - 1)] (({Range#-})) could be used instead: ary[range - 1] The translation methods would not handle certain endpoint types specially, they would just pass the call on. Here's an example implementation in Ruby: class Range def +(other) Range.new(self.begin + other, self.end + other, exclude_end?) end def -(other) Range.new(self.begin - other, self.end - other, exclude_end?) end end =end -- https://bugs.ruby-lang.org/ Unsubscribe: