Search
Close this search box.
Search
Close this search box.

Ruby on Rails Chapter 4: Rails Flavored Ruby

Share This Post

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

Current360 2024 Predictions crystal ball

2024 Predictions

Thanks to everyone who responded to our 2024 Predictions survey last month. While the sample size wasn’t quite the size of a Pew or Nielsen,

Tradition and digital media crown become digital

The King is dead.
Long Live the King.

No we’re not talking about Charles VII or his father Charles VI. Instead, we’re recognizing the passing of the baton after years of shifts from

Contact Us

"*" indicates required fields

I am not a robot
Ed Sharp Current360 headshot

Ed Sharp

Ed brings 15 years of traditional and digital media sales experience to the agency, giving us a perspective most agencies don’t have. When he’s not working or seeking new knowledge, Ed hangs out with his wife, two kids, two dogs, one cat, and a hamster. And yes, the cat and hamster are best friends.

Chaney Given

Chaney is a talented and accomplished designer and illustrator, who has expanded his skill set to include motion graphics and video editing. With nearly a decade of experience, his client work includes Waterstep, Baptist Health, the Archdiocese of Louisville Catholic Schools, First Harrison Bank, and many more