To fix the code, you need to make the following corrections:
:str
to :strng
, since :str
is a reserved word in Ruby.argumenterror
to ArgumentError
, as ArgumentError
is the correct class name for Ruby's built-in argument error.self.
to str
inside the slices
method, as you need to access the instance variable.Here's the corrected code:
main.rb147 chars6 lines
This fix resolves the syntax error and handles the case where the given argument n
is greater than the length of the strng
.
gistlibby LogSnag