G
Giles Bowkett
So I've got this file-checking script:
def check
ok = true
for_every_app do |app,app_info|
ok = File.exists?(app_info[:root])
end
ok
end
And it has a bug, which is that if it evaluates a good file after a
bad file, it'll return true for the whole list.
So here's my suggested change:
def check
ok = true
for_every_app.values.each do |app_info|
ok = File.exists?(app_info[:root]) if ok
end
ok
end
Because if we have one false value, then the whole test is
unnecessary. It's basically like a short-circuit operator.
But I think there's a better way to do it with map.
Something like
File.exists?(for_every_app.values.map{|x| x}
I think I'm way off, though. How do I get that right?
--
Giles Bowkett
Blog: http://gilesbowkett.blogspot.com
Portfolio: http://www.gilesgoatboy.org
Tumblelog: http://giles.tumblr.com/
def check
ok = true
for_every_app do |app,app_info|
ok = File.exists?(app_info[:root])
end
ok
end
And it has a bug, which is that if it evaluates a good file after a
bad file, it'll return true for the whole list.
So here's my suggested change:
def check
ok = true
for_every_app.values.each do |app_info|
ok = File.exists?(app_info[:root]) if ok
end
ok
end
Because if we have one false value, then the whole test is
unnecessary. It's basically like a short-circuit operator.
But I think there's a better way to do it with map.
Something like
File.exists?(for_every_app.values.map{|x| x}
I think I'm way off, though. How do I get that right?
--
Giles Bowkett
Blog: http://gilesbowkett.blogspot.com
Portfolio: http://www.gilesgoatboy.org
Tumblelog: http://giles.tumblr.com/