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.

Set up a Ruby project with RSpec

11/12/17  Public, Ruby General, Testing / TDD

First make sure you have rspec and byebug installed:

➜  byebug -v
  Running byebug 9.1.0
➜  rspec -v
RSpec 3.6
  - rspec-core 3.6.0
  - rspec-expectations 3.6.0
  - rspec-mocks 3.6.0
  - rspec-rails 3.6.1
  - rspec-support ...

1 vote - harrylevine

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:

config/code_schools.yml

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)
or

2 - from ...

1 vote - harrylevine