Ruby – :Symbols and “Strings”

I’m no ruby expert.
Actually i only know enough to write a bit of chef recipes.
If you read enough chef recipes you’ll notice a syntax like the following occur often

default[:mario][:powerup] = "mushroom"

and sometimes you’ll see it as

default["luigi"]["powerup"] = "fireflower"

So what’s the difference?

SYMBOL

A symbol is immutable. This means you’re not reassigning values to it later. It stays as is, like a hillbilly in a trailer home.
:bowser

STRING

A string is mutable. This means you can keep changing the value of it on the fly. Like a gigolo in a bad economy.
“bowser”
 

All of this information was stolen from another extremely useful and thorough blog at: www.robertsosinski.com
He’s exponentially better at explaining this than i am.

Advertisements

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