Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring the code #4

Open
wants to merge 31 commits into
base: dev
Choose a base branch
from
Open

Refactoring the code #4

wants to merge 31 commits into from

Conversation

barackm
Copy link
Collaborator

@barackm barackm commented Oct 21, 2021

In this PR I have implemented the following

  • Refactor the student and teacher logic into a separate folder keeping ruby best practices
  • Refactor the rentals logic into a separate folder keeping the ruby best practices
  • Applied YAGNI, KISS, and DRY rules
  • Applied the Single-responsibility Principle

@barackm barackm requested a review from safafa October 21, 2021 16:52
Copy link
Owner

@safafa safafa left a comment

Choose a reason for hiding this comment

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

STATUS: CHANGES REQUESTED ♻️

Hi @barackm, You did a great job so far 👏🏼 👏🏼

  • Well done on separating the logic into separate files

However, here are some points that you need to work on to get your project approved.

Required changes :

Check the inline comments.

Optional changes :

Every comment with the [OPTIONAL] prefix is not crucial enough to stop the approval of this PR. However, I strongly recommend you to take them into account as they can make your code better.

Cheers and Happy coding!👏👏👏

Feel free to leave any questions or comments in the PR thread if something is not 100% clear.

Please, do not open a new Pull Request for re-reviews. You should use the same Pull Request submitted for the first review, either valid or invalid unless it is requested otherwise.


As described in the Code reviews limits policy you have a limited number of reviews per project (check the exact number in your Dashboard). If you think that the code review was not fair, you can request a second opinion using this form.

people/main.rb Outdated
@@ -0,0 +1,58 @@
# rubocop:disable Metrics\CyclomaticComplexity, Metrics/MethodLength
Copy link
Owner

Choose a reason for hiding this comment

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

  • Kindly remove this comment to enable the linters and modify your code to fix the errors. Linters help you write clean code.
  • Kindly do the same in all the other files where linters are disabled.

people/main.rb Outdated
Comment on lines 22 to 49
def create_person
print 'Do you want to create a student (1)
or a teacher (2)? [Input the number]: '
option = gets.chomp

case option
when '1'
print 'Age: '
age = gets.chomp

print 'Name: '
name = gets.chomp

print 'Has parent permission? [y/n]: '
parent_permission = gets.chomp == 'y'

student = Student.new(age, name, parent_permission)
@people << student
when '2'
print 'Age: '
age = gets.chomp

print 'Name: '
name = gets.chomp

print 'Specialization: '
specialization = gets.chomp

Copy link
Owner

Choose a reason for hiding this comment

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

  • I think this method needs refactoring. Currently, the method has many responsibilities which go against code best practices especially the SOLID principles. You can check this link to better understand the concept. Kindly refactor this method, by distributing its code into small methods each with a single responsibility.

rentals/main.rb Outdated
Comment on lines 8 to 28
def create_rental(books, people)
puts 'Select a book from the following list by number'
books.each_with_index { |book, index| puts "#{index}) Title: #{book.title}, Author: #{book.author}" }

book_index = gets.chomp.to_i

puts 'Select a person from the following list by number (not id)'
people.each_with_index do |person, index|
puts "#{index}) [#{person.class}] Name: #{person.name}, ID: #{person.id}, Age: #{person.age}"
end

person_index = gets.chomp.to_i

print 'Date: '
date = gets.chomp

rental = Rental.new(date, books[book_index], people[person_index])

@rentals << rental
puts 'Rental created successfully'
end
Copy link
Owner

@safafa safafa Oct 21, 2021

Choose a reason for hiding this comment

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

  • Kindly refactor this function. As I mentioned in the previous requested change it goes against best code practices DRY and SOLID principles. For example, you can make use of the list_books and list_people methods you already created instead of repeating the same blocks inside this method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants