Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9013645
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T03:19:12+00:00 2026-06-16T03:19:12+00:00

Basically, I’m really stuck. I’ve got this text where I need to do like

  • 0

Basically, I’m really stuck.

I’ve got this text where I need to do like this:
*print prompt
file_again = STDIN.gets.chomp()
txt_again = File.open(file_again)
puts txt_again.read()*

and basically get text from .txt file printed on my console!

Using File.open() directly from irb, but then attempting:

 File.open("ex15_sample.txt")

^ I assume it opens but I still end up nowhere. I mean, it’s not marked as a variable and I can’t print it.

If I’ll use:

txt = File.open("ex15_sample.txt")

I’ll get some error in the first place, so I can’t use print txt later on.

Exercise is from http://ruby.learncodethehardway.org/book/ex15.html and I’m trying to do optional stuff so I don’t end up nowhere as with codeschool beginners lesson I did earlier on.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T03:19:13+00:00Added an answer on June 16, 2026 at 3:19 am

    I have created a file ex15_sample.txt in …/Ruby/zintlist/irb.

    1.8.6 :082 > File.open("ex15_sample.txt")
    Errno::ENOENT: No such file or directory - ex15_sample.txt
        from (irb):82:in `initialize'
        from (irb):82:in `open'
        from (irb):82
        from :0
    1.8.6 :086 > Dir.getwd
     => "/.../Ruby/prod/spec" 
    1.8.6 :087 > Dir.chdir('../../zintlist/irb')
     => 0 
    1.8.6 :088 > Dir.getwd
     => "/.../Ruby/zintlist/irb" 
    1.8.6 :089 > File.open("ex15_sample.txt")
     => #<File:ex15_sample.txt> 
    1.8.6 :090 > 
    

    attempting File.open(“ex15_sample.txt”) I assume it opens

    Within irb, usually you don’t need to assume, you have an immediate answer.

    1.8.6 :090 > txt = File.open("ex15_sample.txt")
     => #<File:ex15_sample.txt> 
    1.8.6 :091 > puts txt.read()
    This is stuff I typed into a file.
    It is really cool stuff.
    Lots and lots of fun to have in here.
     => nil 
    1.8.6 :092 > 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically I need some text like: I have an ice cream cone. You are
Basically this is a program which I take a text file with some code
Basically I need to get older version of a file in the repository without
basically I want to validate whether or not a text box is a certain
Basically, I have a list of delivery checkboxes one for deliver to this address
Basically I saw this page THIS PAGE and if you scroll up and down
Basically, this is a noob question. Forgive. :( Every example in books or on
Basically I am trying to do this: <Trigger Property=Item Value={c:CollectionView.NewItemPlaceHolder}> But the syntax is
Basically what I am after is this, var foo = 'I am foo!'; alert(window['foo']);
Basically I just need the effect of copying that HTML from browser window and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.