ruby 这是测验1。我只通过哈希部分制作了它。也不能让我的数组只打印一次。
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ruby 这是测验1。我只通过哈希部分制作了它。也不能让我的数组只打印一次。相关的知识,希望对你有一定的参考价值。
# This is our first week's !quiz Let's find out what we know.
#
# The ideal range of your motor cycle speed 20 - 55. Over 55 is SCAREE!
# Check if your moto_speed is within that range using boolean (&&, ||)
# operators and comparison operators (== =< >= !=)
# if your moto_speed variable is in the right range print out a good
# message, aka "Wheee!" Otherwise print out an appropriate response.
# Your code goes below:
#Q if ...
# Make a method that checks your moto speed when called
# ___________________________
def check_speed (mph)
if
mph > 20 && mph < 55
puts "Wheee!"
elsif mph < 20
puts "Booooring!"
else
puts "Jesus, Mary and Joseph!"
end
end
check_speed(60)
# ___________________________
# Make a method to start your bike! It should print out "vrooom!"
# when it's called
# your code below:
#___________________________
def bike_start(start)
if start == "go"
puts "vroooom!"
end
end
puts bike_start("go")
#___________________________
# You're the leader of the pack.
# Create an Array of 3 motorcycle makes!
# ___________________________
my_convoy = ["Triumph", "Indian", "Harley"]
# Loop through your convoy and print out each motorcycle's make
# Your code below:
my_convoy.map { |x| p my_convoy }
# ___________________________
# You need to keep track of your gang.
# Create 3 separate Hashes containing riders' info. like so:
rider1 = { :name => "Guy", :helmet => "pink", :height => "5'2\"" }
rider2 = { :name => "Sylvester", :helmet => "sparkly", :height => "6'5\"" }
rider3 = { :name => "Alejandro", :helmet => "rainbow", :height => "5'8\"" }
# Then a larger Hash containing all riders
my_gang = {:guy => "Guy", :sylvester => "Sylvester", :alejandro => "Alejandro"}
# #___________________________
# # Loop through your gang and print out each rider's name & helmet color using a block.
# Your code below:
puts my_gang[:name]
my_gang.each do |key, value|
puts value[:name]
end
# *** I got to here *** ^NC
# Now for each rider add their motorcycle to their Hash,
# assume they are in the same order as your Array
# use a loop. Your code below:
# Define an Class to represent each gang member
# It should include methods to set their name and motorcyle make
# When say_name(name) is called the rider's name is printed out
#Q Class Rider
# def initialize(name, moto_model)
# end
# def say_name(rider)
# end
#Q end
# A fellow student is noticing that instances of his new Foo class are missing
# their @bar instance variable
#Q class Foo
# attr_reader :bar
# def intialize(bar)
# @bar = bar
# end
# end
# foo = Foo.new('value of bar')
#Q foo.bar # TODO value is missing!
# Fix this code so it prints “hello”
#
#Q class Bar
# def say_something
# puts 'hello'
# end
# end
# bar = Bar.new
#Q bar.hello
# Final Challenge:
# 1. initialize 3 new instances of class Rider
# 2. add these to a new Hash
# 3. loop through the riders Hash and call say_name for each rider.
# Hint: you will need an attr_accessor in Rider to call it's method
# Your code below:
以上是关于ruby 这是测验1。我只通过哈希部分制作了它。也不能让我的数组只打印一次。的主要内容,如果未能解决你的问题,请参考以下文章