I'm trying to create a multi-dimensional array of characters in Ruby, and it works, but it's a More beautiful way?
def initial (text) @map = array.New I = 0 text.split ("\ n"). Every do X | @map [i] = x.scan (/./) i + = 1 end # @ map = text end # creator
@map = text.split (" \ n "). Map {| X | X.scan (/./)} # Approach is a little better, needs at least 1.8.7 @map = text.lines.map {| X | X.scan (/./)}
Comments
Post a Comment