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

My ruby refresher solutions #229

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

meta-morpho-sys
Copy link

No description provided.

end

# turn a positive integer into a negative integer. A negative integer
# stays negative
def make_numbers_negative(number)
num = number
num > 0 ? num * -1 : num

Choose a reason for hiding this comment

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

Use num.positive? instead of num > 0.

# keep only the elements that start with an a: use regular expression
def select_elements_starting_with_a(array)
arr = array
arr.select { |item| item =~ /\Aa/ }

Choose a reason for hiding this comment

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

Use String#start_with? instead of a regex match anchored to the beginning of the string.

end

# keep only the elements that start with an a: use regular expression
def select_elements_starting_with_a(array)

Choose a reason for hiding this comment

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

Method Object#select_elements_starting_with_a is defined at both lib/questions.rb:2 and lib/questions.rb:8.

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