Asked 12 years, 7 months ago
Viewed 33k times
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>'
Jason FB
6,05844 gold badges4343 silver badges8181 bronze badges
asked Jan 16, 2013 at 4:14
KlorthoKlortho83311 gold badge99 silver badges1212 bronze badges
1Starting 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>'
answered Feb 5, 2023 at 14:47
Jason FBJason FB6,05844 gold badges4343 silver badges8181 bronze badges
5You 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.
answered Jan 16, 2013 at 4:16
Matheus MoreiraMatheus Moreira17.1k33 gold badges7272 silver badges112112 bronze badges
4Start asking to get answers
Find the answer to your question by asking.
Ask questionExplore related questions
See similar questions with these tags.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4