Leon Bogaert wrote:
> This would work:
> 
> i = 0; dir = "/home/leon/"; test = Array.new; test = 
> Dir.new(dir).entries.map! { |x| x =~ /filezilla$/ ? x : next  }; 
> test.compact
> 
> Is the .compact needed? Can't I get rid of that?

Also, next is used skip the rest of the code in a block.  For instance:

(1..4).each do |x|
  next if x==2
  puts x
end

--output:--
1
3
4

On the other hand, using next as the last statement in a block does 
nothing:

(1..4).each do |x|
  puts x
  next
end

--output:---
1
2
3
4

...except screw up the return value of the block:

results = (1..4).collect do |x|
  x if x != 2
  next
end

p results

--output:---
[nil, nil, nil, nil]

For methods like collect that use the block's return value, the next 
statement ruins the results array.
-- 
Posted via http://www.ruby-forum.com/.