yermej / gmail.com wrote:
> On Jun 30, 11:00 pm, 12 34 <rubyfo... / web.knobby.ws> wrote:
>> I want to see if any element of an array is equal to a file extension
>>
> 
> I would use Array's include? method:
> 
> ext_not_to_move = ['jpg', 'pdf', 'mrw']
> if ext_not_to_move.include? File.extname(fn).downcase
>   # do stuff
> end
> 
> Jeremy

As I said, this appealed to me, but it's not working and now that I look 
at it more it didn't make sense to this Ruby newbie.

if ext_not_to_move.include? File.extname(fn).downcase

It probably is OK, but I wasn't sure of the syntax (although I don't get 
an error). So I changed it to

if extNot2move.include?(File.extname(fn).downcase)

But this is always false. This construct has the advantage I could
puts #{extNot2move.include?(File.extname(fn).downcase)}

I've puts the File.extname(fn).downcase seperately, and it looks good to 
me. I have some that should be true.

Partial output (::: are not Ruby, just separtors in the puts):

extNot2move.class is an Array and the elements are 
.jpg,.pdf,.mrw,.png,.psd,.tif,.gif,.pict

extNot2move.include?(File.extname(fn).downcase) is false ::: Filename 
is: /Volumes/2001/Tioga OCSS.x.tif ::: File.extname(fn).downcase is .tif

extNot2move.include?(File.extname(fn).downcase) is false ::: Filename 
is: /Volumes/2001/BirdScript.pict ::: File.extname(fn).downcase is .pict

Thanks for any more help.

-- 
Posted via http://www.ruby-forum.com/.