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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T17:36:54+00:00 2026-06-09T17:36:54+00:00

I’m writing a program in Ruby for the first time (I’m using RubyMine as

  • 0

I’m writing a program in Ruby for the first time (I’m using RubyMine as my IDE), having previously coded mostly in Java.

When programming in Java, I used to regularly ‘run’ my code after each bit of functionality I had added to it, just to check that it worked properly.

I’m trying to do that with Ruby, but I’m having a little bit of difficulty.

I have the following class, which I will be using as the menu for my program, so it is where I want the user to start off when they run the program:

class Application
  # To change this template use File | Settings | File Templates.
  def initialize
    mainMenu
  end

  def navigateTo(what)
    what.new.display
    mainMenu
  end

  def mainMenu
    puts "What would you like to do?
      1: Add module to a scheme
      2: Remove module from a scheme
      3: Query modules
      4: Modify module
      5: Register a student on a scheme
      6: Remove a student from a scheme
      7: Register a student on a module
      8: Remove a student from a module"
case gets.strip
  when "1"
    navigateTo Module
    addModule
  when "2"
    navigateTo Module
  when "3"
    navigateTo Module
  when "4"
    navigateTo Module
  when "5"
    navigateTo Student
  when "6"
    navigateTo Student
  when "7"
    navigateTo Student
end
end
end

However, when I run the class, the console displays a line stating that it’s running it, but then the next line is “Process finished with exit code 0”

I can’t work out why this is? In Java, there was a main method, which was where the program would always go for instruction on what to do when it was run… but as far as I can tell with Ruby, there’s no need for a main method? If this is the case, how can I run what I’ve written so far to check that I’ve written it correctly?

*UPDATED**

Ok, I’ve added in the line

Application.new

as suggested, and that’s brilliant- the menu now prints out. I selected option 1 from the menu, and this line was printed out in the console:

#<Module:0x1bd2c90>What would you like to do?

followed by a printout of the menu again.

Option 1 should navigate to my Module class, which looks like this:

class Module
  # To change this template use File | Settings | File Templates.
  @@moduleScheme = nil
  @@moduleYear = nil
  #@moduleTitle = ""

  def self.moduleYear
    @@moduleYear
  end

  def initialize(v)
    @val = v
  end
  # Set and get the @val object value
  def set (v)
    @val = v
  end
  def get
    return @val
  end

  def addModule
    moduleName = Module.new(30)
    moduleRefNo = Random(100)
    #moduleTitle = @moduleTitle
    moduleYear(4)

    print "What is the name of the module you would like to add?"
    moduleName = gets
    moduleRefNo
    printf "Which year does the module belong to?"
    @@moduleYear = gets
    puts "#{moduleName}, belonging to #{@@moduleYear} has been added to the system, with reference number #{moduleRefNo}."
    navigateTo Application

  end

  def addModuleToScheme
    moduleName.moduleScheme = schemeName
  end
  def removeModuleFromScheme
    moduleName.moduleScheme = nil
  end

  def queryModule

  end

end

Once the the user has selected option 1 from the main menu, and the program has navigated to the Module class, I expected it to run that class fully, i.e. display the prompts to the user, and read in whatever they type on the keyboard, then navigate back to the menu, as indicated by the line

navigateTo Application

at the end of my ‘addModule’ function. However, for some reason, it seems to either not be navigating to the Module class, or just skipping straight to the end of it. Can anyone point out what I’m doing wrong here?

  • 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-09T17:36:55+00:00Added an answer on June 9, 2026 at 5:36 pm

    When you run a ruby file, it will run the file from beginning to end. In your file, you are just defining a class, so it will create that class in ruby, then do nothing, since you are not telling it to instantiate a instance of that class. At the end of your file, add Application.new, which will create an instance of that class, and, looking at your code, will print and receive input

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

Sidebar

Related Questions

We're building an app, our first using Rails 3, and we're having to build
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have thousands of HTML files to process using Groovy/Java and I need to
I'm making a simple page using Google Maps API 3. My first. One marker
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We are using XSLT to translate a RIXML file to XML. Our RIXML contains

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.