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

  • SEARCH
  • Home
  • 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 7843059
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T16:27:42+00:00 2026-06-02T16:27:42+00:00

I am writing this code for a CS assignment in Ruby. I am just

  • 0

I am writing this code for a CS assignment in Ruby. I am just beginning in Ruby so I don’t know much about it but I keep getting a no method error from this code like this:

V:\CS 300 RubyAssignment\lib\rubyAssignment.rb:13:in `categorize': undefined method `line' for #<File:ruby1.txt (closed)> (NoMethodError)
    from V:\CS 300 RubyAssignment\lib\rubyAssignment.rb:11:in `open'
    from V:\CS 300 RubyAssignment\lib\rubyAssignment.rb:11:in `categorize'
    from V:\CS 300 RubyAssignment\lib\rubyAssignment.rb:30

The code is below but I get a feeling my text files are in the wrong place. I use a NetBeans Ruby plugin and I don’t know if my text files should be in the projects source file folder, test file folder or libraries folder in netbeans? It might be as simple as that any ideas?

# This program reads a file line by line,
# separating lines by writing into certain text files.
# PPQ - Pangrams, Palindromes, and Quotes

class PPQ
  def categorize
    file_pangram = File.new('pangram.txt', 'w')
    file_palindrome = File.new('palindrome.txt', 'w')
    file_quotes = File.new('quotes.txt','w')

    File.open('ruby1.txt','r') do |file|
      while line = file.gets
        if(file.line.reverse == file.line)
          file_palindrome.write line
          if(file.line.contains('a'&&'b'&&'c'&&'d'&&'e'&&'f'&&'g'&&'h'&&'i'&&'j'&&'k'&&'l'&&'m'&&'n'&&'o'&&'p'&&'q'&&'r'&&'s'&&'t'&&'u'&&'v'&&'w'&&'x'&&'y'&&'z'))
            file_pangram.write "file.line"
          else
            file_quotes.write "file.line"
          end
        end
      end
      file.close
      file_pangram.close
      file_palindrome.close
      file_quotes.close
    end
  end
end
my_ruby_assignment = PPQ.new
my_ruby_assignment.categorize
  • 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-02T16:27:43+00:00Added an answer on June 2, 2026 at 4:27 pm

    The clue’s in the error message!

    undefined method line

    In your while loop you’re reading a line from file via gets, then storing it in line. This code:

    if(file.line.reverse == file.line)
    

    is therefore incorrect — you don’t need the file. prefix! Ruby thinks you’re trying to call the line method of the file object, which it doesn’t have. That’s why it’s giving you the error it did…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a homework assignment, just for all that want to know. I'm writing
I am writing this code that one function calls itself recursively. But I am
I just recently found myself writing this line of code, which i did not
I'm writing a simple piece of code in ruby, but it's not working the
I was writing this code for a C program that transforms letters to lower
Suppose, I have a connected socket after writing this code.. if ((sd = accept(socket_d,
I am writing some code to perform explicit linking to a DLL. This code
Say I have this sample code I'm writing for a Python lesson I'm holding:
I copy and paste code from this URL for creating and reading/writing a proc
I am writing code that catches this OutOfMemoryException and throws a new, more intuitive

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.