The code you provided has a few errors. Here's the corrected version:
main.rb170 chars6 lines
Struct
when creating a new structure.Struct.new
should be defined using do
and end
instead of {}
.raise
instead of argumenterror
to raise an ArgumentError
exception.each_char
and each_cons
are methods that can be used for iterating over characters and consecutive slices, respectively.map
method is used to join each consecutive slice into a string.Now, you can use the series
structure and call the slices
method:
main.rb99 chars3 lines
This will output an array of consecutive slices of length 2 from the given string.
Note: It is important to make sure the member variable name is correctly spelled when accessing it within methods. In your code, it should be @strng
, not strng
.
gistlibby LogSnag