Jesus Castello

  • Ruby Developer

Popular

ruby tricks

11 Ruby Tricks You Haven’t Seen Before

1. Deep copy When you copy an object that contains other objects, like an Array, only a reference to these objects is copied. You can see that in action here:

Using the Marshal class, which is normally used for serialization, you can create a ‘deep copy’ of an object.

The results:

2. […]

ruby procs and lambdas

The Ultimate Guide to Blocks, Procs & Lambdas

Understanding Blocks Blocks are very prevalent in Ruby, you can think of them as little anonymous functions that can be passed into methods. Blocks are enclosed in a do / end statement or between brackets {}, and they can have multiple arguments. The argument names are defined between two pipe | characters. If you have […]

Mastering Ruby Arrays

Arrays are a fundamental data structure that stores data in memory. In Ruby you can store anything in an array, from strings to integers and even other arrays. The elements in an array are accessed using their index, which starts at 0. This is what an array containing the words “cat”, “dog” and “tiger” would […]

Recent Posts

Recursion and Memoization in Ruby

Have you ever wondered if there is an alternative to iteration? Well I have good news for you: there is, and it’s called recursion. Recursive functions are those that keep calling themselves until they hit an end goal (also known as the base case). The idea is that after each function call we make some […]

Static Analysis in Ruby

If you want to know something about your source code, like the name and line number of all your methods, what do you do? Your first idea might be to write a regexp for it, but what if I told you there is a better way? Static analysis is a technique you can use when […]

Debugging your Ruby Programs

How often does your program do exactly what you want the first time around? Many times our programs won’t work like you expect, so we have to use the art of debugging ruby to help us finding out why. You may be familiar with the following error message:

As you know, this means that […]

Using Ruby Threads

Using ruby threads you can make your applications do multiple things at the same time, making it faster. In MRI (Matz’s Ruby Interpreter) you will only benefit from threads in i/o bound applications. This limitation exists because of the GIL (Global Interpreter Lock), alternative Ruby interpreters like JRbuy or Rubinius can take full advantage of […]

Mastering Ruby Regular Expressions

Ruby regular expressions (regex for short) let us find specific patterns inside strings, with the intent of extracting that data for further processing. Two common use cases for regular expressions are validation and parsing. For example, think about an email address, with regular expressions we can define what a valid email address looks like. That […]