-1

I'm pretty new to Ruby. I want to create a file by writing:

file.new "test.txt", "w" 

And de result is:

NameError: undefined local variable or method 'file' for main:Object from (irb):4 from c:/Ruby21/bin/irb:11:in '<main>' 

I don't know what it means. And another question if I may: How do I say in what folder I want to save the file?

1

3 Answers 3

1

You are writing file with a lower case f, which means you are accessing a local variable or a method. In order to access the File class, you must write it with a upper case F:

File.new 'test.txt', 'w' do |file| file.write 'Some text.' end 
Sign up to request clarification or add additional context in comments.

Comments

0

It should be File, not file.

File.new "test.txt", "w" 

Comments

0

file isn't defined, you have to use File:

File.new "test.txt", "w" 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.