Mask Article

In this challenge, your task is to write the following methods:

  • mask_article which 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></strike>.

For example:

> 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):

screen-shot-2016-12-07-at-6-14-03-pm

Notes:

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”

 

Advertisements
Mask Article

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s