Holy Hash’s Batman!

Let’s Hash Things Out

So this week went really well. I feel like I have really fine tuned my understanding of ‘iterations‘¬†with a focus on the ‘.each‘ method. It isn’t a method that you would want to use in ALL situations, but in many it makes good sense!

For instance, let’s say we have a hash. A hash is basically a slightly more complex and certainly more interesting version of an Array (which is just a collection of data that is stored in one variable – i.e. new_array = ["mike","is","cool"]. Seriously, I’m cool.

Now, this hash is going to store Acronyms and their associated full title. The hash value will have an associated key and value. In the example below, “USA” – is a key & “United States of America” – is the value. This is known as a key/value pair.

michael bay.png

Sorry, but the action sequences are a little much. Except for The Rock. Godspeed.

Back to the wonderful world of iterations and hashes! So, we want to display everything in our hash. With .each methods, we are going ‘around the race track‘ for as many times as there are elements in the array or hash. If there are 4 elements, like in this example, it will go around 4 times. If there were 10, it would go around 10x and so on.

Now, this is good if we want to display EVERYTHING, right? Otherwise, a ‘while‘ loop would be in order, because we could stop it once we get what we want out of it. Nice and easy.

Check out these resources:


There is also another thing I learned, which is slightly complex and slightly in the domain of Freud or Nietzsche, and that is Symbols. In Ruby we have these things called symbols, and they look like this…


It looks like a string, and it kind of is. In Ruby it is preceded by a colon (:) but it is worth noting that when equating a symbol to a value the shorthand would be something like this … (mike: "name"). Now, something that makes them very valuable to developers is that they are immutable. This means that they can not change throughout the duration of the code, which also means they only take up one spot of memory which drastically increases the response time of your program and the application as a whole. With strings, each instance takes up a different spot in the memory of your application, and the larger your programs and more complex they become, the more apparent this bottleneck makes itself known.

Check out these resources:

Submit a comment

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