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 4619864
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T02:28:56+00:00 2026-05-22T02:28:56+00:00

I am attempting to learn Ruby by converting a Java program to Ruby, but

  • 0

I am attempting to learn Ruby by converting a Java program to Ruby, but I’ve been coming up with an error surrounding this block of code:

  def create
    @user_input = String.new()
#   @word_arr = Array.new

  print "Enter the text to be converted to pig latin, EOF to quit: "
    while gets do
      STDOUT.flush
      @user_input = gets.chomp
      @word_arr = @user_input.string.split(' ')
      @word_arr.each { |x| puts x.engToLatin() + ' '}
      print "EOF to Quit"
      @user_input = ""

    end

  end

I’ve been getting this error:

EnglishToPigLatin.rb:14:in `create': private method `chomp' called for nil:NilClass (NoMethodError)
    from EnglishToPigLatin.rb:60

This is the area around line 60:

#if __FILE__ == $0

  mg = EnglishToPigLatin.new
  mg.create

#end

Essentially what I am trying to do is while there is still input, get that input, split it up into individual words, and run each word through a Pig Latin conversion method.

  • 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-05-22T02:28:57+00:00Added an answer on May 22, 2026 at 2:28 am

    It looks like you’re trying to get input inside of your loop.

    Try

    loop do
      user_input = gets.chomp!
      word_arr = user_input.to_s.split(' ')
      word_arr.each { |x| puts x.engToLatin() + ' '}
      puts "EOF to Quit"
    end
    

    Otherwise you’re trying to get the next line of input when there isn’t one. Additionally, do isn’t necessary for a while statement.
    You also don’t need to reset @user_input to ''.

    And since this is all in a block, you don’t need to use instance variables, unless the methods you call need them.

    Also your conditional is always true. gets will block until it gets a line of input. You can use loop for an infinite loop that ends on an interrupt.

    Also, you needn’t flush STDOUT if you use a puts for the last line there instead of a print.

    The whole thing could be a script or a method in a module. An instance doesn’t even need to be made. And if you do, instead of using two lines with your mg.create, you should define an initialize method. This is used as a constructor then, and whatever you set when you create an instance should be put there.

    It can all be done like this:

    loop do
      puts gets.chomp.split(' ').map{ |x| x.engToLatin() }.join(' ')
      puts "EOF to Quit"
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been attempting to learn C in my spare time, and other languages (C#,
I'm attempting to learn Ruby on Rails. I'm pretty confident with the basics and
I have recently begun the process of trying to learn Ruby/Rails and have been
I am attempting to learn OCaml by using compiled code instead of the top-level;
I am new to programming but attempting to learn. Im running visual studio 2010
I'm attempting to learn a little more about handling sockets and network connections in
I am attempting to learn oCaml and am having an issue as to why
When attempting to compile my C# project, I get the following error: 'C:\Documents and
I am trying to set myself up on a mac to learn Ruby on
Attempting to learn from doing an implementation of Quicksort, I cannot find out why

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.