AnthonyW
AnthonyW

Reputation: 1998

Ruby Dir.exists? undefined method

I looked the Dir.exists? method up in the documentation and I believe I am using it correctly, yet at each call I am hit with this error:

undefined method `exists?' for Dir:Class (NoMethodError)

Am I overlooking something incredibly obvious? Below is the related code.

#!/usr/bin/ruby
ARGV.each do |dir|          # Arguements are directory names.
    if !Dir.exists?(dir)
#dosomething
end
end

EDIT:

Using File.directory? instead of Dir.exists? fixes my program, yet does not explain this error.

Upvotes: 4

Views: 6859

Answers (1)

Dan Tao
Dan Tao

Reputation: 128307

Which version of Ruby are you using? The documentation link you provided is for Ruby 2.0. The Dir.exists? method was not available in 1.8.

You can check your Ruby version from the command line with:

ruby -v

Or from an IRB session, check the value of the RUBY_VERSION constant.

If you're interested in using newer/multiple Ruby versions on your machine, I recommend looking into RVM or rbenv.

Upvotes: 8

Related Questions