3.2.0 :002 > File.exists?("xyz")
(irb):2:in `<main>': undefined method `exists?' for File:Class (NoMethodError)
Did you mean? exist?
from /Users/jason/.rvm/rubies/ruby-3.2.0/lib/ruby/gems/3.2.0/gems/irb-1.6.2/exe/irb:11:in `<top (required)>'
from /Users/jason/.rvm/rubies/ruby-3.2.0/bin/irb:25:in `load'
from /Users/jason/.rvm/rubies/ruby-3.2.0/bin/irb:25:in `<main>'
Starting in Ruby 3.2.0 the exists?
(with an S) alias for exist?
seems to has been removed.
With Ruby 3.2.0, be sure to use the no-S exist?
% rvm use 3.1.3
Using /Users/jason/.rvm/gems/ruby-3.1.3
[email protected] /Users/jason/Work/Hot_Glue/Example Apps/AltLookup1 [main]
% irb
3.1.3 :001 > File.exist?("xyz")
=> false
3.1.3 :002 > File.exists?("xyz")
=> false
3.1.3 :003 > exit
[email protected] /Users/jason/Work/Hot_Glue/Example Apps/AltLookup1 [main]
% rvm use 3.2.0
Using /Users/jason/.rvm/gems/ruby-3.2.0
[email protected] /Users/jason/Work/Hot_Glue/Example Apps/AltLookup1 [main]
% irb
3.2.0 :001 > File.exist?("xyz")
=> false
3.2.0 :002 > File.exists?("xyz")
(irb):2:in `<main>': undefined method `exists?' for File:Class (NoMethodError)
Did you mean? exist?
from /Users/jason/.rvm/rubies/ruby-3.2.0/lib/ruby/gems/3.2.0/gems/irb-1.6.2/exe/irb:11:in `<top (required)>'
from /Users/jason/.rvm/rubies/ruby-3.2.0/bin/irb:25:in `load'
from /Users/jason/.rvm/rubies/ruby-3.2.0/bin/irb:25:in `<main>'
You forgot the question mark (?
) at the end:
File.exist? 'foo'
File.exists? 'foo'
In general, methods which answer questions will always end with a question mark.
In this case, the method is asking File
the does 'foo' exist?
question. The class will return the answer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With