In this challenge, your task is to write the following methods:
mask_articlewhich appends strike tags around certain words in a text. The method takes 2 arguments: A string and an array of words. It then replaces all the instances of words in the text with the modified version.
- A helper method
strike, given one string, appends strike off HTML tags around it. The strike off HTML tag is
> strike("Meow!") # => "<strike>Meow!</strike>" > strike("Foolan Barik") # => "<strike>Foolan Barik</strike>" > mask_article("Hello World! This is crap!", ["crap"]) "Hello World! This is <strike>crap</strike>!"
Apply the helper method in completing your main method.
This is the solution (which I still don’t fully grasp yet):
gsub “creates a temporary copy” of a variable, and gsub! changes the variable. For example
name = John
- name.gsub(/0/, “e”) => “Jehn”
- puts name => “John”
- name.gsub!(/0/, “e”) => “Jehn”
- puts name => “Jehn”