Skip to content

Instantly share code, notes, and snippets.

@durrellchamorro
Created November 14, 2015 00:01
Show Gist options
  • Save durrellchamorro/5320966876dd7220402b to your computer and use it in GitHub Desktop.
Save durrellchamorro/5320966876dd7220402b to your computer and use it in GitHub Desktop.
Series
class Series
attr_reader :digits
def initialize(string_of_digits)
@digits = string_of_digits.chars.map(&:to_i)
end
def slices(slice_size)
fail ArgumentError, "Slice size cannot exceed caller's digit size." if slice_size > digits.size
result = []
until digits.size < slice_size
result << digits.slice(0, slice_size)
digits.shift(1)
end
result
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment