-
-
Notifications
You must be signed in to change notification settings - Fork 954
mentoring notes for Bob on the Ruby track #2391
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
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
15b4cd7
mentoring notes for Bob on the Ruby track
Budmin df1e507
Whitespace changes
Budmin c0617cc
added missing word
Budmin c3c65ca
minor grammer changes
Budmin 6de7c01
added short problem overview
Budmin c9bcd5a
Update tracks/ruby/exercises/bob/mentoring.md
Budmin f1c1028
Exercism uses one sentence per line
Budmin 9626542
removed freeze on regular expressions
Budmin cf9ec78
Added sentence about prefixing predicate methods
Budmin 9df0b2b
Updated `Using end_with?` header
Budmin 3a1a141
Update mentoring.md
Budmin 5dbf8dc
Update mentoring.md
Budmin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| # Mentoring | ||
|
|
||
| The key to this exercise is to look for patterns in a string, and extracting the specific criteria in order to make return the correct response. | ||
| Most solutions look for `yelling` and `asking` criteria. | ||
|
|
||
| ## Resonable Solutions | ||
|
|
||
| ### Using String Methods | ||
|
|
||
| ```ruby | ||
Budmin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| module Bob | ||
|
|
||
| def self.hey(remark) | ||
| remark = remark.strip | ||
| question = remark.end_with?('?') | ||
| yelling = remark == remark.upcase && remark != remark.downcase | ||
|
|
||
| if remark.empty? | ||
| 'Fine. Be that way!' | ||
| elsif yelling && question | ||
| "Calm down, I know what I'm doing!" | ||
| elsif yelling | ||
| 'Whoa, chill out!' | ||
| elsif question | ||
| 'Sure.' | ||
| else | ||
| 'Whatever.' | ||
| end | ||
| end | ||
|
|
||
| end | ||
| ``` | ||
|
|
||
| ### Using Regular Expressions | ||
|
|
||
| ```ruby | ||
| module Bob | ||
|
|
||
| SILENCE = /\A\s*\z/ | ||
| ASKING = /\?\s*\z/ | ||
| SHOUTING = /\A[^A-Za-z]*[A-Z]+(?:[^a-z]*)\z/ | ||
| def self.hey(input) | ||
| case | ||
| when silence?(input) | ||
| 'Fine. Be that way!' | ||
| when asking?(input) && shouting?(input) | ||
| "Calm down, I know what I'm doing!" | ||
| when asking?(input) | ||
| 'Sure.' | ||
| when shouting?(input) | ||
| 'Whoa, chill out!' | ||
| else | ||
| 'Whatever.' | ||
| end | ||
| end | ||
|
|
||
| class << self | ||
| protected | ||
| def silence?(input) | ||
| SILENCE.match?(input) | ||
| end | ||
|
|
||
| def shouting?(input) | ||
| SHOUTING.match?(input) | ||
| end | ||
|
|
||
| def asking?(input) | ||
| ASKING.match?(input) | ||
| end | ||
| end | ||
| end | ||
| ``` | ||
|
|
||
Budmin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ## Common Suggestions | ||
|
|
||
| ### Predicate Methods | ||
|
|
||
| The names of predicate methods (methods that return a boolean value) should end in a question mark (i.e. `Array#empty?`). | ||
|
|
||
| Students should avoid prefixing predicate methods with auxiliary verbs such as `is_yelling` or `has_question` | ||
| These words are redundant and inconsistent with the style of boolean methods in the Ruby core library, such as `empty?` and `include?`. | ||
|
|
||
| Resources about style: | ||
| - https://rubystyle.guide/#bool-methods-qmark | ||
| - https://rubystyle.guide/#bool-methods-prefix | ||
|
|
||
| ### Checking for a Question Mark With Indices | ||
|
|
||
| If the student is using indices or extra transforms to check for a question mark (e.g., `remark[-1] == '?'`, `remark.chars.last == '?'`, etc.), guide them toward `String#end_with?`. | ||
| It is more readable and explicitly communicates the intent of the check. | ||
|
|
||
| ### Usage of Regular Expressions | ||
|
|
||
| Regular expressions are powerful, but can be illegible. | ||
| While regex is common in Ruby code, if the student is having a hard time understanding regex it may be better to guide them toward a solution that uses simpler String methods. | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.