Difference between include vs extend

03/05/18  Public, Ruby General

Great article by https://twitter.com/feministy that explains the difference between using include vs extend andself, when using modules:

http://lizabinante.com/blog/modules-and-self-in-ruby/

1 vote - harrylevine

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

Workflow for upgrading Rails versions

12/25/17  Public, Rails General

First, read through the Rails "A Guide for Upgrading Ruby on Rails".

In general, you can follow the steps in this [Ruby on Rails Upgrade Guide blog post](http://nithinbekal.com/post...

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

Can call multiple `expects` in an `it` block without stopping on failure

11/30/17  Public, Testing / TDD

By adding :aggregate_failures to the end of anit statement, you can call multiple expects in that it block, and if any of them fail, the tests keep testing.

For example, in the this spec, if expect(Post.count).to eq 4 fails, the test ...

1 vote - harrylevine

How to open a link in the same new named tab, every time

11/14/17  Public, Tricks, Other Languages

When you want a link to open up in a new tab, you simply set the target to _blank:

<a href="http://www.starfall.com/" target="_blank">Starfall</a>

But what if you have an index view containing all your Posts, and you want...

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

Disabling and re-enabling a rubocop rule for a specific set of code

11/07/17  Public, Testing / TDD

For example, if this rule is in your .rubocop.yml file:

Style/RedundantSelf:
  Description: Don't use self where it's not needed.
  StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-self-unless-required
  Enabled: true
`...

1 vote - harrylevine

Checking for rubocop offenses in a given file

11/07/17  Public, Testing / TDD

You can check what is/is not passing rubocop for a given file by calling:

rubocop app/whatever/whatever/my_file.rb

You can get even more output by passing it the -D flag, which adds the actual name of the cop.

rub...

1 vote - harrylevine