Skip to content

Ruby Refresher weekend PR#215

Open
KyeBracey wants to merge 41 commits intomakersacademy:masterfrom
KyeBracey:master
Open

Ruby Refresher weekend PR#215
KyeBracey wants to merge 41 commits intomakersacademy:masterfrom
KyeBracey:master

Conversation

@KyeBracey
Copy link

All done except 99 bottles (I'd like to never do that for the third time).

KyeBracey added 30 commits June 24, 2017 15:46
# count the number of words in a file
def word_count_a_file(file_path)
file = File.open(file_path, "r")
file.each_line do | line |

Choose a reason for hiding this comment

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

Space before first block parameter detected.
Space after last block parameter detected.

# where 'special character' means anything apart from the letters
# a-z (uppercase and lower) or numbers
def check_a_string_for_special_characters(string)
/\W/ === string

Choose a reason for hiding this comment

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

Reverse the order of the operands /\W/ === string.

lib/questions.rb Outdated
def titleize_a_string(string)
articles = ['a', 'and', 'the']
string.split.each_with_index.map do |word, index|
index > 0 && articles.include?(word) ? word : word.capitalize!

Choose a reason for hiding this comment

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

Use index.positive? instead of index > 0.

lib/questions.rb Outdated
# pairing up elements. e.g. ['a', 'b', 'c', 'd'] becomes
# {'a' => 'b', 'c' => 'd'}
def convert_array_to_a_hash(array)
odds_and_evens = array.partition.with_index { |number, index| index.even? }

Choose a reason for hiding this comment

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

Unused block argument - number. If it's necessary, use _ or _number as an argument name to indicate that it won't be used.

lib/questions.rb Outdated
# stays negative
def make_numbers_negative(number)
return number if number < 0
number - number*2

Choose a reason for hiding this comment

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

Surrounding space missing for operator *.

lib/questions.rb Outdated
# turn a positive integer into a negative integer. A negative integer
# stays negative
def make_numbers_negative(number)
return number if number < 0

Choose a reason for hiding this comment

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

Use number.negative? instead of number < 0.

lib/questions.rb Outdated
# round up - so 'apple' becomes 'app'
def get_first_half_of_string(string)
return string[0...(string.length/2)] if string.length.even?
string[0..(string.length/2).round]

Choose a reason for hiding this comment

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

Surrounding space missing for operator /.

# 'banana' becomes 'ban'. If the string is an odd number of letters
# round up - so 'apple' becomes 'app'
def get_first_half_of_string(string)
return string[0...(string.length/2)] if string.length.even?

Choose a reason for hiding this comment

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

Surrounding space missing for operator /.

lib/questions.rb Outdated

# remove instances of nil (but NOT false) from an array
def remove_nils_from_array(array)
array.select { |element| element != nil }

Choose a reason for hiding this comment

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

Use reject instead of inverting select.


# remove instances of nil (but NOT false) from an array
def remove_nils_from_array(array)
array.reject { |element| element == nil }

Choose a reason for hiding this comment

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

Prefer the use of the nil? predicate.

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.

2 participants