Ruby General

Not learning Ruby is a bit like knowing how to fly a plane…on the ground.
Without Ruby, there is no Rails. Ruby is the backbone. It would be wise to have a reasonably solid Ruby foundation before adding on Rails. After that you will hit a certain point where you’ll realize that, in order to enact a desired feature for your web app, you’ll need to apply more advanced Ruby tactics. This will also come into play when trying to understand other developer’s code. As you move further down your Ruby learning path, your eyes will open wider to how much you can do with Ruby, and all the elegant and clever ways people apply Ruby to accomplish a given task. You will want to remember these. This stack is dedicated to capturing these moments of Ruby enlightenment.

Iterate over a .yml file's contents

07/01/17  Public, Rails General, Ruby General

Let's assume that the .yml file (i.e. code_school.yml) is located in this directory:


You'll grab the path to the file, and load its contents:

config = Rails.root + 'config/code_schools.yml'

1 vote - harrylevine

Dealing with a LocalJumpError

06/20/16  Public, Troubleshooting, Ruby General

This is commonly caused by having return called within a block.

Here is an example. This example triggered an Airbrake error of type LocalJumpError:

task :decrement_taken_pto_...

1 vote - harrylevine

Using the ruby #inject method

06/16/16  Public, Ruby General

I had this method to start with:

NON_DEDUCTIBLE_REASONS = ['Jury Duty', 'Bereavement']

def self.attendance_status_ids
  ids = []

  NON_DEDUCTIBLE_REASONS.each do |reason|
    ids << AttendanceStatus.find_by_name(reason.to_s.t...

1 vote - harrylevine

Find all the available instance methods for a given class

03/07/16  Public, Ruby General

To see all the instance methods available on a given class

1 - from a class object call .instance_methods on the class (i.e. User.instance_methods)

2 - from ...

1 vote - harrylevine

Passing a block into a method, as a parameter - Using Proc and &block

02/23/16  Public, Ruby General

In order to pass a block into a method, as a parameter:

  1. Create a Proc and put the block's contents inside of it
  2. Pass the Proc in as parameter, placing an & in front of the variable's name
  3. In the method, the block parameter will...

1 vote - harrylevine