Erik Trautman logo crest shield seal

Erik Trautman

“Everything you can imagine is real.”
-- Pablo Picasso

Ruby Explained: Arrays

This post will get into Arrays, which is where you really start seeing some of Ruby's cool programmer-friendly features

Arrays are almost as ubiquitous as strings. You'll be working with them all the time to help store data, everything from the names of all your users to coordinates on a game board. An array is an all-purpose bucket into which you can put pretty much anything.

Here, you'll learn the basics of creating arrays, how to manipulate them in a dozen different ways, and some best practices for working with arrays. Note that we'll be learning even more about how to dig around inside of arrays in a future lesson, so if you're excitedly waiting to better understand #each, #map and others like them, we're almost there! If not... you will be.

Read More…


Ruby Explained: Strings

This post will cover strings and all the interesting things you can do with them in Ruby.

Strings are a huge part of web programming and you'll run into them everywhere from variable names to user input to giant gobs of HTML text to handling big dictionary files. They're actually pretty simple at the core but, for being just a jumble of characters, strings have some pretty cool properties in Ruby and you can do a whole lot to manipulate them.

This post should give you an appreciation for the ways you can mess with strings and some of the handy methods that Ruby gives you along the way to make your life easier.

Strings are just made up of individual characters and denoted with quotes. > I confuse Ruby and probably throw an error but > "I do not because I have quotes"

Read More…


Ruby Explained: Objects and Methods

This post will cover objects, methods and some things about classes in Ruby

"Everything in Ruby is an Object" is something you'll hear rather frequently. "Pretty much everything else is a method" could also be said. The goal here is for you to see the Matrix... that everything in Ruby is an Object, every object has a class, and being a part of that class gives the object lots of cool methods that it can use to ask questions or do things. Being incredibly object-oriented gives Ruby lots of power and makes your life easier.

Think of every "thing" in Ruby as a having more than meets the eye. The number 12 is more than just a number... It's an object and Ruby lets you do all kinds of interesting things to it like adding and multiplying and asking it questions like > 12.class or > 12+3

Read More…


Ruby Explained: Numbers, Operators and Expressions

This post will be very brief look at some of the basic numbers, operators, and expressions in Ruby

When doing mathematical operations, Ruby expects the result to be the same type as the inputs, so dividing two integers by each other will produce an integer... whether you want to or not:

> 5 / 3
=> 1  

To fix this, you need to make one of the inputs a different data type that can handle decimals, like a floating point number (float):

> 5.0 / 3               # as long as one of them is a float...
=> 1.6666666666666667   # ... the result is a float

Converting between integers and floats is easy -- just use to_i and to_f respectively:

> 5.0234.to_i
=> 5
> 5.to_f
=> 5.0

Because Ruby is so flexible, it lets you do some quirky things like multiplying completely different data types together in a way that you sort of think you should be able to but never expected to actually be able to do:

Read More…