Skip to content

Instantly share code, notes, and snippets.

@lyuehh
Last active December 16, 2015 01:09
Show Gist options
  • Save lyuehh/5353023 to your computer and use it in GitHub Desktop.
Save lyuehh/5353023 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
path = ENV['PATH'].split(':')
all = []
path.each do |p|
all.push(Dir.entries(p))
end
puts all.flatten.select{ |a| a != '.' && a != '..' }
@lyuehh
Copy link
Author

lyuehh commented Apr 10, 2013

#!/usr/bin/env ruby
path =  ENV['PATH'].split(':')

all = []
path.each do |p|
  all.push(Dir.entries(p))
end
puts all.flatten.select{ |a| a != '.' && a != '..' }.sort

排序一下比较好...

@lyuehh
Copy link
Author

lyuehh commented Apr 10, 2013

puts ENV['PATH'].split(':').inject([]){|a,b| a.push(Dir.entries(b))}.flatten.select{ |a| a != '.' && a != '..' }.sort

恩,其实可以写成一行的

@lyuehh
Copy link
Author

lyuehh commented Apr 10, 2013

System getEnvironmentVariable("PATH") split(":") reduce(a,b,a push(Directory with(b) items reduce(a,b,a push(b name),list())), list()) flatten  select(a, a != "." and a != "..") sort

io语言版本...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment