0
0
Rubyprogramming~10 mins

Class declaration syntax in Ruby - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to declare a class named Car.

Ruby
class [1]
end
Drag options to blanks, or click blank then click option'
Acar
BCar
Cvehicle
DClassCar
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase names for classes.
Using names that do not start with a capital letter.
2fill in blank
medium

Complete the code to define a method named start inside the class.

Ruby
class Car
  def [1]
    puts 'Car started'
  end
end
Drag options to blanks, or click blank then click option'
Arun
Bgo
Cbegin
Dstart
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different method name than requested.
Capitalizing method names (they should be lowercase).
3fill in blank
hard

Fix the error in the class declaration by completing the blank.

Ruby
class [1]
  def initialize
    @speed = 0
  end
end
Drag options to blanks, or click blank then click option'
Avehicle
Bcar
CCar
Dspeed
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase class names.
Using variable names instead of class names.
4fill in blank
hard

Fill both blanks to create a class Bike with a method ride that prints 'Riding'.

Ruby
class [1]
  def [2]
    puts 'Riding'
  end
end
Drag options to blanks, or click blank then click option'
ABike
BCar
Cride
Dstart
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up class and method names.
Using incorrect capitalization.
5fill in blank
hard

Fill all three blanks to create a class Plane with a method fly that prints the speed stored in @speed.

Ruby
class [1]
  def [2]
    puts "Flying at #{ [3] } km/h"
  end
end
Drag options to blanks, or click blank then click option'
APlane
Bfly
C@speed
Dspeed
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting the @ in instance variable.
Using wrong method or class names.