Created
February 20, 2015 18:39
-
-
Save BobGu/144030229bfc6184cb03 to your computer and use it in GitHub Desktop.
This file contains 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
def make_bold(text) | |
#find all the words or phrases that are surrounded by ** | |
#flatten to return just an array instead of an array of arrays | |
matches = text.scan(/\*{2}(.*?)\*{2}/).flatten | |
#replace those words in our text with strong tags by finding the pattern again | |
#continue to do this block of code while there is a match for words or phrases surrounded by ** | |
while text.match(/\*{2}(.*?)\*{2}/) | |
text.sub!(/\*{2}(.*?)\*{2}/, "<strong>#{matches[0]}</strong>") | |
#delete the first match from our matches array since we have already used it to replace our text | |
matches.delete_at(0) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment