Ruby on Rails Chapter 4: Rails Flavored Ruby

Share This Post

Share on facebook
Share on linkedin
Share on twitter
Share on email

This is the chapter where the real fun starts. Your introduction to the Rails Console.

Consider this console as the worry-free sandbox you used to play in as a child. If you built your mote wrong, you could simply kick sand back into it or walk away. With the Rails Console, if you get your code wrong, simply use Ctrl-C to break that last command or Ctrl-D to exit the console all together.

The console is great for new developers of all levels or developers new to Ruby. It allows you to test ideas and theories without the fear of permanent repercussions of damaging your precious database.

This comes in handy if you recursively delete your entire hard drive. (An action I will neither confirm nor deny happened while I was attending Transylvania)

Interpolation within a string.

When I wrote my first RoR program, I just jumped in. I started laying down the codes with no prior knowledge of Ruby or Rails. Turns out, that’s not the best approach with anything—especially completely new concepts which I’ve previously covered.

So, let’s start with interpolation. According to Merriam-Webster, interpolate means—to put (something) between other things or parts. But for our purposes, it means to display the associated variable within a string.

For example, if I put:

myVar = "Jerrod is awesome"

in the console and then typed:

"Who is awesome? {myVar}"

the output will be:

"Who is awesome? Jerrod is awesome"

Common programming mistake

A common error/misconception among new programmers is the difference between a double quote (“) and a single quote (‘). In most cases with Ruby, they behave exactly the same.

However, had I entered:

‘Who is awesome? {myVar}’

The output would have been

‘Who is awesome? {myVar}’

As you can see, this doesn’t do us any good. Some of you may even be asking how setting a variable and then outputting it is of any use to a programmer, anyway.

Usage case of interpolation

The practice of interpolating a variable within a string would be most handy when you receive input from the user. We have all experienced this on a site where you have signed up and once you logged in a personalized message is displayed, like:

"Welcome back, Jerrod."

Everyone would see “Welcome back, ” with the name variable changing.

This is only the tip of the iceberg when it comes to the capabilities of Ruby on Rails. After this chapter I felt comfortable enough in the language to stop going through the tutorial. You will see these lessons (and many more) in action, with the sites we’re creating here at Current360 using Ruby on Rails.

More To Explore

Creative

Getting B2B Results on Social Media

There are plenty of well known B2C brands that are killing it on social media. Wendy’s has gained thousands of followers and fans with their

Contact Us

  • This field is for validation purposes and should be left unchanged.

Rob Womack

If there’s anyone who can honestly say, “Been there, done that,” it’s Rob. After traveling the world for seven years in his 20’s, Rob went to LA and started working in film production. Then it was off to New York, where he learned how to program, which eventually brought him back home to Louisville to build websites. At Current360, Rob heads up our in-house production studio, creating all things digital for our clients — videos, commercials, radio spots, and a lot more. 

When he’s at home, Rob likes to create things like homemade kombucha and music.