From: "Jesús Gabriel y Galán" Date: 2010-10-29T01:54:43+09:00 Subject: Re: undefined method `find' for.:Module On Thu, Oct 28, 2010 at 6:42 PM, John Hammink wrote: > Hello, > > I am quite new at Ruby (we use it for test automation in conjunction > with Cucumber, where it works great!)  but as a stand-alone, I'm finding > myself more productive with Python.  Maybe that's just me. > > I have to confess I do not know what the issue is. When I try to run the > attached script (note:  this example is copied  *EXACTLY* from Ruby > Cookbook)  I am given the following error at Windows cmdline: > > E:\Sounds\Digital>ruby Froop.rb > Froop.rb:6:in `match': undefined method `find' for Froop:Module > (NoMethodError) >        from Froop.rb:12:in `
' You are calling find as a standalone method, but the find library creates a Find class: require 'find' module Froop def match(*paths) matched=[] Find.find(*paths) { |path| matched << path if yield path } return matched end module_function :match end Froop.match("./") { |p| ext = p[-4...p.size]; ext && ext.downcase == "mp3" } This works, or at least, doesn't raise an error about the find method. > > Note that the Froop.rb is in same directory from where I am attempting > to run it.   Ruby doesn't seem to recognize it's own require statement: > > require 'find' > > on the first line of the file, which is positively baffling. > > Note, that when I try to only put my function in the file and call Froop > from the command line (how I originally tried to do it), that's a lost > cause too: > > E:\Sounds\Digital>irb > irb(main):001:0> require 'Froop' > LoadError: no such file to load -- Froop >        from :29:in `require' >        from :29:in `require' >        from (irb):1 >        from C:/Ruby192/bin/irb:12:in `
' > irb(main):002:0> Froop.match("./") { |p| ext = p[-4...p.size]; ext && > ext.downcase == "mp3" } > NameError: uninitialized constant Object::Froop >        from (irb):2 >        from C:/Ruby192/bin/irb:12:in `
' > irb(main):003:0> > > Seriously what gives?  I'm ready to put Ruby in the Bin and switch to > Python, but my heart won't let me...yet.  :( You are using ruby 1.9.2, which has removed "." from the LOAD_PATH. You can use: require './Froop' or add "." to the load path yourself: $: << "." Don't lose faith in Ruby, you'll be glad in the end if you persevere :-) Jesus.