Skip to content

Instantly share code, notes, and snippets.

@purp
Last active January 24, 2016 17:06
Show Gist options
  • Save purp/fe713ca7bd0127aa377d to your computer and use it in GitHub Desktop.
Save purp/fe713ca7bd0127aa377d to your computer and use it in GitHub Desktop.
Expand a two-element array by an interval
class Array
def expand(interval=1)
raise "Can only expand two-element arrays" if self.size != 2
raise "Can only expand numeric arrays" unless self.first.kind_of?(Numeric) && self.last.kind_of?(Numeric)
result = [self.first]
while result.last < self.last do
next_value = result.last + interval
if next_value < self.last
result << next_value
else
result << self.last
end
end
result
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment