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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T11:12:18+00:00 2026-06-04T11:12:18+00:00

class Airplane attr_reader :weight, :aircraft_type attr_accessor :speed, :altitude, :course def initialize(aircraft_type, options = {})

  • 0
class Airplane
  attr_reader :weight, :aircraft_type
  attr_accessor :speed, :altitude, :course

  def initialize(aircraft_type, options = {})
    @aircraft_type  = aircraft_type.to_s 
    @course = options[:course.to_s + "%"] || rand(1...360).to_s + "%" 
  end 

How I can use minimum and maximum allowable values ​​for the hash in initialize from 1 to 360?

Example:

airplane1 = Airplane.new("Boeing 74", course: 200)
p radar1.airplanes
=> [#<Airplane:0x000000023dfc78 @aircraft_type="Boeing 74", @course="200%"]

But if I set to course value 370, airplane1 should not work

  • 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-04T11:12:20+00:00Added an answer on June 4, 2026 at 11:12 am

    This could be refactored i’m sure but this is what i came up with

    class Plane
    
      attr_reader :weight, :aircraft_type
      attr_accessor :speed, :altitude, :course
    
      def initialize(aircraft_type, options = {})
        @aircraft_type = aircraft_type.to_s 
        @course = options[:course] || random_course
        check_course  
      end
    
      def check_course
       if @course < 1 or @course > 360
          @course = 1
          puts "Invalid course. Set min"
         elsif @course > 360
          @course = 360
          puts "Invalid course. Set max"
         else
          @course = @course
         end
       end
    
       def random_course
        @course = rand(1..360)
       end
    
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an abstract class Airplane, and two classes PassengerAirplane and CargoAirplane, which extend
class Hello @hello = hello def display puts @hello end end h = Hello.new
I am trying to achieve Model-view separation. My airplane is a class. While developing
class ITestType(object): Sample interface type __metaclass__ = ABCMeta @abstractmethod def requiredCall(self): return class TestType1(object):
Ok, so I have a model like this: class Airplane(models.Model): tail = models.ForeignKey(Tails) wheel
class example: def exampleMethod(self): aVar = 'some string' return aVar In this example, how
class test: def __init__(self, val): self.val = val self.val.lower() Why doesn't lower() operate on
If I had a class Airplane and a class Wing, if there was a
class CreateMatches < ActiveRecord::Migration def self.up create_table :matches do |t| t.integer :result_home t.integer :result_away
I'm coding a class that's supposed to model airplane cargo and I'm having trouble

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.