fix: `series = struct.new(:str) { def slices(n) n > @str.length ? argumenterror.new("no!") : str.each_char.each_cons(n).map(&:join) end }` in ruby

To fix the code, you need to make the following corrections:

  1. Change :str to :strng, since :str is a reserved word in Ruby.
  2. Change argumenterror to ArgumentError, as ArgumentError is the correct class name for Ruby's built-in argument error.
  3. Add self. to str inside the slices method, as you need to access the instance variable.

Here's the corrected code:

main.rb
series = struct.new(:strng) {
  def slices(n)
    n > @strng.length ? ArgumentError.new("no!") : @strng.each_char.each_cons(n).map(&:join)
  end
}
147 chars
6 lines

This fix resolves the syntax error and handles the case where the given argument n is greater than the length of the strng.

related categories

gistlibby LogSnag