From: "Jesús Gabriel y Galán" Date: 2010-10-29T02:47:29+09:00 Subject: Re: undefined method `find' for.:Module On Thu, Oct 28, 2010 at 7:33 PM, John Hammink wrote: > Hi Jesus, > > Sorry I didn't see your earlier reply. > > Unfortunately this is what I get when I run your code from CMD: > E:\Sounds\Digital>ruby Froop.rb > Froop.rb:15:in `block in
': undefined method `size' for > nil:NilClass (NoMethodError) >        from Froop.rb:8:in `block in match' >        from C:/Ruby192/lib/ruby/1.9.1/find.rb:41:in `block in find' >        from C:/Ruby192/lib/ruby/1.9.1/find.rb:40:in `catch' >        from C:/Ruby192/lib/ruby/1.9.1/find.rb:40:in `find' >        from Froop.rb:8:in `match' >        from Froop.rb:15:in `
' > > And this is what I get when I import to IRB and run FROOP block > separately: > > E:\Sounds\Digital>irb > irb(main):001:0> require './Froop' > => true > irb(main):002:0> Froop.match("./") { |p| ext = p[-4...p.size]; ext && > ext.downcase == "mp3" } > NoMethodError: undefined method `size' for nil:NilClass >        from (irb):2:in `block in irb_binding' >        from E:/Sounds/Digital/Froop.rb:8:in `block in match' >        from C:/Ruby192/lib/ruby/1.9.1/find.rb:41:in `block in find' >        from C:/Ruby192/lib/ruby/1.9.1/find.rb:40:in `catch' >        from C:/Ruby192/lib/ruby/1.9.1/find.rb:40:in `find' >        from E:/Sounds/Digital/Froop.rb:8:in `match' >        from (irb):2 >        from C:/Ruby192/bin/irb:12:in `
' > irb(main):003:0> OK, well, we've moved one step further :-). What this means is that the block is being called with a nil value, which is causing p inside the block to be nil, and when you try to call p.size it complains that nil doesn't have that method. I'm not able to reproduce it, even in an empty folder (at least the block gets passed "./"), so maybe it's a Windows thing, I'm using Ubuntu, and it works perfectly for me. By the way, there's a better way to check the extension: $ irb irb(main):001:0> require './Froop' => true irb(main):003:0> Froop.match("./") { |path| File.extname(path).downcase == ".rb" } => ["./Froop.rb"] Hope this helps, Jesus.