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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T17:24:01+00:00 2026-06-03T17:24:01+00:00

I don’t mean how do I include ActiveRecord, but let me explain. I want

  • 0

I don’t mean how do I include ActiveRecord, but let me explain.

I want to have a Game with a difficultyLevelID and a DifficultyLevel Object.

In Rails and ActiveRecord (that’s what I am familiar with) these would be tables and I would have the has_many and belongs_to methods and then I could just use the difficultyLevelID to get things, so difficulty level could be Game.difficulty_level.name

If I am just doing a Ruby program with no database and I want to use that relationship, i.e. I want Game to have an ID for difficulty level and the level name itself to be in a difficulties class, how do I do that (create, maintain and query the relationship) just with Ruby so that I can say get the game difficulty level name?

  • 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-03T17:24:02+00:00Added an answer on June 3, 2026 at 5:24 pm

    There was no answer in 20 hours so I’ve posted my own.

    class Soduko
      attr_accessor :name, :rows, :columns, :difficulty_level
      def initialize // will probably move to parameters as defaults.
        @rows= 9
        @columns= 9
        @name= 'My Soduko'
        @difficulty_level= 'Medium'
      end
    
      def initial_number_count
        DifficultyLevel.start_with_numbers('Medium')
      end
    
    end
    
    class DifficultyLevel
    
      def self.start_with_numbers(difficulty_level)
        case difficulty_level
          when 'Easy'
          then 30
          when 'Medium'
          then 20
          when 'Hard'
          then 10
          else 20
        end
    
      end
    
    end
    

    and of course the tests:

    require './soduko'
    
    describe Soduko, '.new' do
    
      before { @soduko_board  = Soduko.new }
    
      it "Should allow for a new Board with 9 rows (default) to be created" do
        @soduko_board.rows.should == 9
      end 
    
      it "Should allow for a new Board with 9 columns (default) to be created" do
        @soduko_board.columns.should == 9
      end 
    
      it "should have a default difficulty level of 'Medium'" do
        @soduko_board.difficulty_level.should == 'Medium'
      end 
    
      it "should have 10 initial numbers" do
        @soduko_board.initial_number_count.should == 20
      end 
    
    end
    
    describe DifficultyLevel, '.new' do
    
      it "should exist" do
        @difficulty_level = DifficultyLevel.new
      end
    
      # More to be added...
    
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Don't know if I worded the question right, but basically what I want to
Don't know how to explain it better but i'm trying to get a response
Don't ask why but I have the requirement to draw a border around certain
DON'T ASK WHY but... I have a regex that needs to be case insensitive
Don't get me wrong, I want them to get saved. But I always thought
I don't like Jackson. I want to use ajax but with Google Gson. So
I don't have any experience in updating a Rails app and when I google
I don't have much PHP experience and I want to know how to best
Don't know why but I can't find a solution to this. I have 3
don't know better title for this, but here's my code. I have class user

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.