Skip to content

Instantly share code, notes, and snippets.

@mikestone14
Created January 9, 2014 17:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikestone14/8337961 to your computer and use it in GitHub Desktop.
Save mikestone14/8337961 to your computer and use it in GitHub Desktop.

Blocks Lab 1: Hashtag Overload

In this lab, we'll write a short program that will auto-hashtag our tweets for us. Put this line in a new Ruby file:

tweet = "We ate fifty cheeseburgers for lunch"

Your objective is to transform this tweet into the array ["#fifty", "#cheeseburgers", "#lunch"]. You'll need to do three things:

  • Split the tweet into an array of words
  • Select only words that are longer than 3 characters
  • Add a hash mark (#) before each word

You may end up creating some intermediate variables to do this. However, it is possible to do it all on one line!

Extra Challenge

How would you stick the hashtags onto the end of the original tweet to get a hashtagged tweet? For example, "We ate fifty cheeseburgers for lunch #fifty #cheeseburgers #lunch"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment