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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T16:13:58+00:00 2026-06-06T16:13:58+00:00

I understand how classes work and how to make them, but the 2nd extra

  • 0

I understand how classes work and how to make them, but the 2nd extra credit of the exercice says to create a two-class version, in 2 different files.

I tried different things, but I can’t figure out how to make it work…

I don’t know if I’m not searching at the right places, but I can’t find any help on that, nor find any solution…

If anyone could help me on that, it would be much appreciated 🙂

here is the exercice : http://ruby.learncodethehardway.org/book/ex42.html

What I have tried so far :

map.rb
class Map

with all the methods in here (death(), central_corridor(), etc.)

then

engine.rb
class Engine
require './map.rb'

  def initialize(start)
    @quips = [
      "You died. You kinda suck at this.",
      "Nice job, you died... jackass.",
      "Suck a luser."
    ]

    @start = start
    puts "in init @start = " + @start.inspect
  end

  def prompt()
    print "> "
  end

  def play()
    puts "@start => " + @start.inspect
    @next_room = @start

    while true
      puts "\n--------"
      room = method(@next_room)
      @next_room = room.call()
    end
  end

end

a_game = Engine.new(:central_corridor)
a_game.play()

So basically what I did is get the methods used for “actions” in the game (the rooms, death, etc.. and put them in a class Map in map.rb, and then called in engine.rb where i have my class Engine with the “general” methods/variables like prompt, play, start.

The error I get is

engine.rb:24:in `method': undefined method `central_corridor' for class `Engine'

I understand it means ruby tries to find a method “central_corridor” in the class engine, but it’s in the class map in map.rb and I can’t figure out what to do, either it’s some variable modifications or just some things to add… 🙁

  • 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-06T16:13:59+00:00Added an answer on June 6, 2026 at 4:13 pm

    The problem is that you don’t have an instance of class Map, which is what you need to be able to call central_corridor. Add this into initialize:

    @map=Map.new
    

    And change room = method(@next_room) to room=@map.method(@next_room).


    Although this isen’t your question, I have a feeling that if Map never changes (you have methods for everything in the map), that you make all of the methods class methods and just use the class Map for your map. But by good design principles, you should probably make the map have a Hash of lambdas representing the areas. That way, you can have more than one map

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

Sidebar

Related Questions

I am trying to understand Puppet parameterized classes. I have a parameterized class defined
I want to understand the role interface plays in inheritance between two classes. My
I'm trying to understand type patterns and generic classes in Haskell but can't seem
Try to understand WPF. This is my test classes: public partial class MainWindow :
If I have these two classes: class A {} class B : A {}
Using lazy=true in my classes causes my application to work perfectly, but the performance
I do not fully understand classes. I have read the python documentation and several
I am new to OOP and I think I don't understand static classes. I
I have to say I don't understand Scala enumeration classes. I can copy-paste the
I understand that Struts2 Action classes are thread-safe, because the actions are put in

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.