Today I Learned

10 posts by marekpolakowski

Ruby's "Class < OtherClass"

Overview

You can use ruby’s “greater than” and “less than” operators for checking class inheritance.

Foo < Bar
# returns true if Foo is included in Bar's ancestors
# returns false if Foo is a Bar's descendant
# otherwise returns nil

Source: Selleo/pattern - lib/patterns/query.rb

Real life examples:

User < ActiveRecord::Base # => true
ActiveRecord::Base < User # => false
TrueClass < String # => nil

Group console logs

There’s this cool feature in JS console (works in Chrome and Firefox) you can use if you want to log a lot of information, but you’re afraid of JS console getting too crowded. See example:

Code example

console.groupCollapsed("types of components");
console.log(typeof ComponentOne);
console.log(typeof ComponentTwo);
console.log(typeof ComponentThree);
console.groupEnd();

That’s what you’ll get in JS console

image

Using multiple commands on heroku CLI

Need to use multiple heroku CLI commands one after another and don’t want to type -a foo-bar-baz every time?

Type export HEROKU_APP=foo-bar-baz in terminal and then just happily run heroku command on foo-bar-baz application.

heroku pg:backups:capture -a foo-bar-baz

# is equivalent to:

export HEROKU_APP=foo-bar-baz
heroku pg:backups:capture

PS. After that you might want to unset HEROKU_APP to remove variable.