【发布时间】:2014-09-09 16:36:54
【问题描述】:
所以我有我的数组:(这不是元素的确切顺序,只是一个例子)
myArray = {./dir2/chico.html, ./dir2/chico.rb, ./dir1/c.js, ./dir1/g.txt, ./dir1/d.css}
当我使用...进行排序时
myArray.sort
结果未排序...
./dir2/chico.html
./dir2/chico.rb
./dir1/c.js
./dir1/g.txt
./dir1/d.css
我想要的是将所有 dir1 文件放在 dir2 之前。 d.css 应该在 g.txt 之前。为什么不排序?
【问题讨论】:
-
在 Ruby 中这是一个无效的赋值,并且这些不是花括号内的字符串,并且散列被封装在花括号中,而不是数组。
myArray = ['./dir2/chico.html', './dir2/chico.rb', './dir1/c.js', './dir1/g.txt', './dir1/d.css']; myArray.sort => ["./dir1/c.js", "./dir1/d.css", "./dir1/g.txt", "./dir2/chico.html", "./dir2/chico.rb"]所以排序工作正常。
标签: ruby arrays sorting filepath