Skip to content

Instantly share code, notes, and snippets.

@cnruby
Created February 15, 2010 22:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cnruby/305051 to your computer and use it in GitHub Desktop.
Save cnruby/305051 to your computer and use it in GitHub Desktop.
# http://chinaonrails.com/topic/view/3730.html
class Dir
def xget # 传统编写代码方式,目的返回一个Array
n = []
while name = self.read
n << name
end
n
end
def get # Ruby编写代码方式,目的返回一个Array
self.map {|name| name} # 或者 self.map &:to_s
end
end
dir = Dir.open(".")
p dir.get
#p dir.map {|x| x}
dir.close
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment