Today I Learned

If you have ever opened your HTML source in the browser and wondered which templates were rendering which part of the page, this feature is for you.

 # Render template filenames as comments in HTML
 config.action_view.annotate_template_file_names = true


Ruby 2.7 introduced a shorthand syntax (...) for forwarding arguments to methods.

# using args, kwargs, and block arguments
def perform(*args, **kwargs, &block), kws)

# using the new syntax
def call(...)


Useful when you need to accept any number of parameters, but you actually don't care about them or you just want to pass them away to the superclass method.

class Bar
  def do_something(*args)
    puts "Passed args: #{args.inspect}"

class Foo < Bar
  def do_something(*)
end"hello", "world")
#=> Passed args: ["hello", "world"]

Sometimes we do not follow all best guidelines, creating new branches because there is a point that makes no sense if you have just typo in translation and you amend your last commit or you squash your commits, there will be no harm but in situations when you must work with a teammate on sam branch there is one safer solution than

git push --force

`--force-with-lease` refuse to update a branch unless it is the state that we expect; i.e. nobody has updated the branch upstream

git push --force-with-lease


note: this is not a bulletproof solution but is still better than just using `--force`

here is a good article explaining it with potential pitfalls

If you develop gem and want to test changes in real-time without pushing code you could use path instead of git repo but this has few disadvantages if you need a test that code is working on multiple projects you need to add that change to every single project and later remember to remove this, but here come local git repos to rescue.

Simply tell bundler to use local version instead.

$ bundle config local.my_gem ~/projects/my_gem

When you are done with testing just remove the binding.

$ bundle config --delete local.my_gem

Pluck all the ID's for the ActiveRecord relation using the table's primary key

# the same as:
#=> SELECT FROM users


To create a hyperlink in a terminal execute following code:

echo -e '\e]8;;\aEffectiva studio\e]8;;\a'


* some terminals may not support hyperlinks

Use this comments to "tag" commands in terminal so it's easier to find it later.

df -h #disk #useful
git reset HEAD~ #git #undo #undocommit #useful

Than you can use:

history | grep "# useful"

or reverse search with CTRL+R

Template Method is a behavioral design pattern that defines the skeleton of an algorithm in the superclass but lets subclasses override specific steps of the algorithm without changing its structure:

  • abstract 
    Must be implemented by every subclass.
  • optional
    Already have some default implementation, but still can be overridden if needed.
  • hook 
    Optional step with an empty body. 
    Usually, hooks are placed before and after crucial steps of algorithms, providing subclasses with additional extension points.

build_stubbed is the younger, more hip sibling to build; it instantiates and assigns attributes just like build, but that’s where the similarities end. It makes objects look like they’ve been persisted, creates associations with the build_stubbed strategy (whereas build still uses create), and stubs out a handful of methods that interact with the database and raises if you call them. This leads to much faster tests and reduces your test dependency on a database.

Use Factory Girl's build_stubbed for a Faster Test Suite