开发者

More elegant way to write a multi-dimensional array of characters in ruby?

I am trying to make a multi-dimensional array of characters in ruby, and this works, but is there a more elegant way?

def initialize(text)
    @map = Array.new
    i = 0
    text.split("开发者_如何学Go\n").each do |x|
     @map[i] = x.scan(/./)
     i += 1
    end
    #@map = text
  end#constructor


@map = text.split("\n").map{|x| x.scan(/./)}

#looks slightly better, needs at least 1.8.7
@map = text.lines.map{|x| x.scan(/./)} 


@map = text.lines.to_a.map { |s| s.chomp.split("") }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜