gistlib
other ruby categories
struct code snippets in ruby
convert it to a struct: `class series def initialize(series) = @series = series def slices(n) raise argumenterror if n > @series.length @series.chars.each_cons(n).map(&:join) end end` in ruby
fix it: `series = struct.new(:string) { def slices(n) = string.each_char.each_cons(n).map(&:join) if n > string.length }` in ruby
give `class grains def self.square(n) 2 ** (n - 1) end` like here: `class phrase < struct.new(:text)` a struct like: in ruby
give it as a struct: `class series def initialize(string) @string = string end def slices(n) raise argumenterror if n > @string.length @string.each_char.each_cons(n).map(&:join) end end` in ruby
what is wrong? `series = struct.new(:strng) { def slices(n) n > @strng.length ? argumenterror : @strng.each_char.each_cons(n).map(&:join) end }` in ruby
gistlib
by LogSnag