This guide examines how you can open up the String class and convert all of the words in a sentence into hashtags that can be utilized via social media outlets.

Summary

Open up the String class in Ruby and build a hashtag generator method.

Exercise File

Code File

Exercise Description

Given a string, implement a method that converts each word into a hashtag and returns a single string of the hashtags.

Sample Input

'fun words that need to be hashtags'

Expected Output

'#fun #words #that #need #to #be #hashtags'

Real World Usage

This is a common feature that you’ll be asked to build if you work on Ruby on Rails applications. Essentially this exercise requires you to be able to split a string into separate components, update the formatting of each element, and then combine the components back together.

Solution

Can be found on the solutions branch on github.

LEAVE A REPLY

Please enter your comment!
Please enter your name here