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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T03:09:38+00:00 2026-06-10T03:09:38+00:00

I’m writing a course management program in Ruby, to assist with managing courses at

  • 0

I’m writing a course management program in Ruby, to assist with managing courses at a university, the modules associated with each course, and the students registered on each of the courses and modules.

Each student can be registered to only one course (or scheme), and can only take modules that are available on their scheme.

At the moment, I have two classes: Application.rb, which is the class I’m using as the menu, to interact with the user, and CourseModules.rb, which is the class where I’m doing all of the work

Application.rb:

class Application
# To change this template use File | Settings | File Templates.
require './courseModules.rb'
def initialize
  mainMenu
end

=begin
  def navigateTo(what)
  what.new(v).display
  mainMenu
  end
=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"
      CourseModules.add_module
    when "2"
      CourseModules.removeModuleFromScheme
    when "3"
      navigateTo CourseModules
    when "4"
      navigateTo CourseModules
    when "5"
      navigateTo Student
    when "6"
      navigateTo Student
    when "7"
      navigateTo Student
  end
end
Application.new
end

CourseModules.rb:

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

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


# Attempt at add_module method on 21/08/2012 at 16:30
def self.add_module
  schemes = {}
  scheme_exists = false
  add_another_scheme = true
  add_another_module = true

  while add_another_scheme
    print "Enter scheme name: "
    scheme_name = gets
    @schemes.has_key?(scheme_name.chop) ? scheme_exists = true : scheme_exists = false

    if !scheme_exists
      @schemes[scheme_name.chop] = []
      puts "Scheme #{scheme_name.chop} has been added to the system"
    else
      scheme_exists = false
      puts "This scheme has already been added"
    end

    while add_another_module
      print "Enter module name: "
      module_name = gets
      @schemes[scheme_name.chop].include?(module_name.chop) ? true : @schemes[scheme_name.chop] << module_name.chop
      print "Add another module? "
      ask_if_user_wants_to_add_another_module = gets
      if(!ask_if_user_wants_to_add_another_module.chop == "y" or ask_if_user_wants_to_add_another_module == "yes")
      add_another_scheme = false
    end

 end

 print "Add another scheme? "
 ask_if_user_wants_to_add_another_scheme = gets
 if !(ask_if_user_wants_to_add_another_scheme.chop == "y" or ask_if_user_wants_to_add_another_scheme.chop == "yes")
   add_another_scheme = false
 end
 puts @schemes

end

 while add_another_module
   print "Enter scheme name: "
   scheme_name = gets
   schemes.has_key?(scheme_name.chop) ? scheme_exists = true : scheme_exists = false

   if !scheme_exists
     print "Enter module name: "
     module_name = gets
     schemes[scheme_name.chop] = module_name.chop
     puts "Scheme #{scheme_name.chop} with module #{module_name} has been added to the system"
   else
     scheme_exists = false
     puts "This scheme has already been added"
     puts "Enter module name: "
     module_name = gets
     schemes[scheme_name.chop] = module_name.chop
     puts "Scheme #{scheme_name.chop} with module #{module_name} has been added to the system"
   end

   print "Add another module? "
   ask_if_user_wants_to_add_another_module = gets
   if !(ask_if_user_wants_to_add_another_module.chop == "y" or ask_if_user_wants_to_add_another_module.chop == "yes")
     add_another_module = false
   end
 end
 puts schemes
 end

end

At the moment, when I run the program from Application.rb, the menu is displayed, and I select option 1 (Add module to a scheme).
I’m then asked to enter the scheme name, which I do, and press Enter.

However, I then get an ‘undefined method’ error in ‘add_module’ for ‘has_key’. It says it’s for ‘nil:NilClass (NoMethodError)

Can someone explain this to me? How would I put it right?

  • 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-10T03:09:40+00:00Added an answer on June 10, 2026 at 3:09 am

    You are making reference to @schemes but you define it as schemes = {}, hence the nil:NilClass (NoMethodError).

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I am writing an app with both english and french support. The app requests
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string

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.