After this week, our time dealing solely with Ruby is over for the rest of the semester. It’s Rails from here on out. To finish off our pure Ruby curriculum, we went through a few concepts that definitely filled some holes in my knowledge.


While working at AlldayEveryday this summer, I saw my first JSON API. It was an unofficial Citibike JSON feed that had a ton of potential for building a cool app - the only problem was that I had no clue how to use it. I searched and searched, but couldn’t figure out how to manipulate it in Ruby. Luckily, Jeff is an incredible teacher and showed us how to easily do this. Admittedly, it was easier than I thought it was going to be, I just wasn’t looking in the right places.

Where the trick lay was in the Ruby URI library and the JSON library. Getting and using data from JSON APIs, such as Google’s geolation API, is as easy as:

```ruby geolocate.rb

google_maps_url = URI.encode(“{city_name}&sensor=false”) read_url = open(google_maps_url).read data = JSON.parse(read_url) ``` So what’s happening here is the URI library is encoding an address I pass it and that response gets opened and is read in the in the read_url variable. That data is then parsed by the JSON library and is returned as a Ruby hash, ready to be maniupulated. To the initiated, this would seem trivial, but this kind of blew my mind. I could now easily have access to any data that was openly available and use it for an app, which to me is a powerful notion.

Object Oriented Programming

This is a concept that, in my attempt at learning to program on my own, I had definitely heard of but didn’t fully understand. This article really helped me understand what it meant to be object oriented.

One of the most important concepts that the article talks about is the idea that every object can be manipulated by sending messages. These messages are what we write as methods and they allow objects to communicate. With every method, there is a sender object and a receiver object. This gave me a better understanding of how data is exchanged in an object oriented language.

The article also explained what the four properties of object oriented programming languages: Absttraction, encapsulation, polymorphism, inheritance.


Abstraction is a process in which data is represented semantically while implementation is hidden. For example, storing data from user input in a variable, making it easier to understand and use later.


When objects communicate with one another, the only thing they know about each other is their interface. All the data and logic is encapsulated within each object. When you really think about it, encapsulation is really a form of abstraction; objects don’t communicate directly with the data and logic within another object.


This is just a fancy word for a simple concept. Polymorphism allows for multiple objects to respond to the same message. For example, a method called name could be implemented for a Person class and a Dog class. When name is called for either object, the same logic is performed, but a different message is returned.


Inheritance allows one class to have the same behavior as another class, while extending that classes specific behavior. For example, the class Dog has a name and and the ability to speak.

``` ruby dog.rb

class Dog def name=(name) @name = name end

def name return @name end

def speak puts “Woof woof.” end end ```

This is good, but if I wanted to create behavior that was specific to each breed, I would need to create a subclass that inherits behavior from the Dog class, but also extends it.

```ruby jack_russell.rb

class JackRussell < Dog def jump_really_high #code for the dog jumping really high end end ``` The < tells us that the JackRussell class inherits behavior from the Dog class.

This obviously isn’t an exhaustive list of object oriented concepts, but it really helped me understand the fundamentals.