Last active
November 28, 2018 19:40
-
-
Save VladHurma/29b9ab1ab5cce2c2faa4c802b629e7c7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
class Goals_result | |
include Comparable | |
def initialize | |
@goals_scored = [] | |
@goals_missed = [] | |
end | |
def self.run | |
new.run | |
end | |
def run | |
initialize_games_results | |
say_user_games_results | |
end | |
private | |
def initialize_games_results | |
(0..19).each do |i| | |
@goals_scored[i] = rand(0..5) | |
@goals_missed[i] = rand(0..5) | |
end | |
end | |
def say_user_games_results | |
(0..19).each do |i| | |
print "#{i + 1}: " | |
check_up_game_result(@goals_scored[i], @goals_missed[i]) | |
end | |
end | |
def check_up_game_result(score, miss) | |
if score == miss | |
show_user_result('Draw!') | |
elsif score > miss | |
show_user_result('Win!') | |
elsif score < miss | |
show_user_result('Lose!') | |
end | |
end | |
def show_user_result(result_by_words) | |
puts result_by_words | |
end | |
end | |
Goals_result.run |
aya-soft
commented
Nov 28, 2018
- Вот тут у метода очень много обязанностей (обход массива, сравнение значений, печать на экран, определение результата)
Вопросы к тебе:
- какой в Руби есть оператор, который при сравнении выдает три значения?
- можно ли здесь использовать case-конструкцию?
Раздели пожалуйста обязанности: обхода, вычисления результата и печать - в разные методы
Вопросы к тебе:
* какой в Руби есть оператор, который при сравнении выдает три значения? * можно ли здесь использовать case-конструкцию?
Comparable вроде(-1,0,1)
Можно
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment