Tips and Tricks (Today I learned)

In this thread you can add any type of tips and tricks. Any feature of some language, framework, terminal, code-editor, the operating system you use, social media platform you use, or even the devtalk. Thing which you just learned, but you wish that you knew it earlier.

(You’re welcome to edit the intro).


Corresponding tweet for this thread:

Share link for this tweet.

While you cannot run ri commands from inside an irb session, you can run ri commands from inside a pry session.

What are ri, irb and pry?

I have seen different (very talented) people saying that it’s abbreviated from different terms, like Ruby Information, Ruby Interactive and Ruby Index. No matter which term it stands for, it’s the Ruby tool for navigating documentation.

Interactive Ruby Shell is a REPL for Ruby.

A runtime developer console and IRB alternative with powerful introspection capabilities (as stated on its Github page). Installable as a Gem.

1 Like

You can run ri from inside IRB if you do this:

def ri(*args)

Now you can do

> ri 'String.length'


That’s nice!
Do we need to run that function every time we open IRB or we can save it somewhere?

1 Like

You can put it in your ~/.irbrc file.

I also have

if defined? Rails
  banner = if Rails.env.production?
    "\e[41;97;1m #{Rails.env} \e[0m "
    "\e[42;97;1m #{Rails.env} \e[0m "

  IRB.conf[:PROMPT][:CUSTOM] = IRB.conf[:PROMPT][:DEFAULT].merge(
    PROMPT_I: banner + IRB.conf[:PROMPT][:DEFAULT][:PROMPT_I]

so that it prints my Rails.env in a different color depending on developer or production.

1 Like

So today I learned, sort of by accident, how to wrap any number of strokes into their separate li html elements.


I use Sublime editor. In there I pressed Ctrl+Shift+p (command pallete) and typed ‘wrap’ and found Emmet’s ‘Wrap with Abbreviation’ function.

At first I just tried ul>li*5. That wasn’t what I wanted. I just thought how could I get to the result I wanted when I started backspacing and when 5 was removed I was left with **ul>li * ** it worked. Good think I noticed. Saved some precious time on googling that stuff.

Gosh, I got so excited.