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.

Require and load a gem in IRB for testing purposes while developing the gem

01/20/18  Public, Ruby General, Gems

  • cd into the root of the gem
  • run bin/console

Done.

Or,

  • cd into the root of the gem
  • run bundle console

Or,

  • cd into the root of the gem
  • run irb -I lib
  • run require "name_of_gem"

For example:

$ i...

1 vote - harrylevine

Benchmarking in the Rails Console

01/01/18  Public, Ruby General, Rails Errors

timing = Benchmark.measure { Post.all }

The various attributes of the object returned (Benchmark::Tms) are provided here.

Here is a sample applicati...

1 vote - harrylevine

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