Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 658
AnthonyW Avatar asked Oct 23 '25 20:10

AnthonyW


2 Answers

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.

like image 179
Dan Tao Avatar answered Oct 26 '25 10:10

Dan Tao


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.

like image 21
Dan Tao Avatar answered Oct 26 '25 10:10

Dan Tao



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!