-
Notifications
You must be signed in to change notification settings - Fork 27
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
. #39
base: master
Are you sure you want to change the base?
. #39
Conversation
parser.rb
Outdated
return :yes | ||
end | ||
} | ||
return :no |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First, some trivial little style things:
- for multi-line blocks, prefer the
do
...end
syntax. - use
return
only for early, i.e. not on the last line of the method - it looks like you're getting the triple-equals from javascript. In ruby, that is actually the case-comparison operator, which happens to work in this case, but will give you unexpected behavior in other cases. What you want is the double-equals.
- in the file below, you're replacing all of the single quotes with double quotes. Ruby-ists typically prefer single quotes to double quotes, when possible. Double quotes in ruby allow for interpolation and various other goodies, and so using single quotes makes it super obvious to readers of code that there's nothing funky going on inside (assuming that there isn't).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Slightly more substantive feedback:
- is there a way you could use the
any?
method instead ofeach
? - you've got the regex, and you've got the splitting. Can't you just use the regex for the splitting?
- does
\b
improve your regex?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Finally, I think there's a one-liner solution here. It might involve:
- making better use of your regex, and
- a ternary for the
:yes
and:no
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know how to do another pull request, but this is the updated code:
def word_in_string?(word, string)
new_string = string.downcase.gsub(/[^a-z]/, " ").split(" ")
new_string.any? { |string| word == string } ? :yes : :no
end
I'm not sure about the regex, I just looked up an example
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, instead of another pull request, you'd typically just tack on another commit (like you did).
You've hit a bunch of my concerns above, but not all of them. Take another read through.
No description provided.