Skip to content

[Horse racing task] Add initialize method and change variable names#4

Open
Slavunderkind wants to merge 3 commits into
masterfrom
horse_racing_solution
Open

[Horse racing task] Add initialize method and change variable names#4
Slavunderkind wants to merge 3 commits into
masterfrom
horse_racing_solution

Conversation

@Slavunderkind

Copy link
Copy Markdown
Owner

No description provided.

@Slavunderkind Slavunderkind requested review from a user and vasil-gochev January 12, 2017 09:24
@Slavunderkind Slavunderkind changed the title Add initialize method and change variable names [Horse racing task] Add initialize method and change variable names Jan 12, 2017
Comment thread horse_racing.rb Outdated
end

def find_difference
strenghts = init_strenghts

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

strengTH :)

Comment thread horse_racing.rb Outdated
attr_accessor :horses_number

def initialize
@horses_number = gets.to_i

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better to use count or size instead of number for variables that express count or size

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, sure 👍

Comment thread horse_racing.rb Outdated
n.times do
pi = gets.to_i
strenghts_array << pi
horses_number.times do

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try using each_with_object. You can also chain it to .times

@Slavunderkind Slavunderkind force-pushed the master branch 4 times, most recently from b8e5d88 to 73f6435 Compare January 17, 2017 14:56
Comment thread Training/Easy/horse_racing.rb Outdated
horses_count.times.each_with_object([]) { |_, result| result << gets.to_i }.sort
end

def start

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of the start method altogether, just use your find_difference function:

obj = HorceRacing.new
answer = obj.start
puts answer

or even

answer = HorceRacing.new.start
puts answer

Comment thread Training/Easy/horse_racing.rb Outdated
@horses_count = gets.to_i
end

def find_difference

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method does two things - it inializes strengths and it also finds their difference. Try to refactor it so that it only does one thing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants