Today, I Learned...

by Justin Campbell

Ruby 2.3.0 Language Changes

Frozen string literal pragma

city = "Philadelphia"
city.frozen? # => false
city << ", PA"
city # => "Philadelphia, PA"
# frozen_string_literal: true

city = "Philadelphia"
city.frozen? # => true
city << ", PA" # RuntimeError: can't modify frozen String

Safe navigation operator

a = 1.23
b = nil

a.round # => 1
b.round # NoMethodError: undefined method `round' for nil:NilClass

a&.round # => 1
b&.round # => nil

nil&.none&.of&.these&.methods&.exist # => nil

Hash#dig/Array#dig

data = {
  users: [
    {
      name: "Justin",
      cats: [
        { name: "Tallie"},
        { name: "Zack"}
      ]
    }
  ]
}

data[:users][0][:cats][0][:name] # => "Tallie"
data[:users][0][:dogs][0][:name] # NoMethodError: undefined method `[]' for nil:NilClass

data.dig(:users, 0, :cats, 0, :name) # => "Tallie"
data.dig(:users, 0, :dogs, 0, :name) # => nil

did_you_mean.gem is bundled

> "abcd".revrse
NoMethodError: undefined method `revrse' for "abcd":String
Did you mean?  reverse
               reverse!
November 17th, 2015
Estimate cost of source code with sloccount
  • shell
November 4th, 2014
Open tmux windows/splits in the current directory
  • shell
  • tmux
October 14th, 2014
Add colors to ls output
  • shell
October 10th, 2014
Disable Pry breakpoints
  • ruby
October 9th, 2014
Stage parts of a file, and review your git commits
  • git
October 6th, 2014
Go to the previous directory in Bash
  • shell
October 2nd, 2014
Lock OS X from the command line/tmux
  • shell
  • tmux
September 29th, 2014
Jump to a character in Vim
  • vim
September 26th, 2014
Jump to the last edit in Vim
  • vim
September 22nd, 2014
Toggle Ruby block syntax with vim-blockle
  • ruby
  • vim
February 11th, 2014
Start an HTTP server with ruby -run
  • ruby
December 2nd, 2013
Close all other Vim buffers
  • vim
November 5th, 2013
ZoomWin for Vim
  • vim
November 1st, 2013
PROMPT_COMMAND, and a simpler git prompt
  • git
  • shell
October 24th, 2013
Git can find refs by relative time
  • git
September 30th, 2013
Ruby 2.1.0 Language Changes
  • ruby
September 23rd, 2013
Run vimtutor to learn Vim
  • vim
September 19th, 2013
Edit multiple things at once in VIM
  • vim
September 9th, 2013
Push to and pop from the workspace stack in IRB
  • ruby
August 12th, 2013
RubyVM::InstructionSequence
  • ruby
July 5th, 2013
Annotate Ruby code in Vim with xmpfilter
  • ruby
  • vim
July 1st, 2013
Use Ctrl+F to bring up history
  • shell
June 17th, 2013
Kill a process by name with pkill
  • shell
June 11th, 2013
Unix Background Jobs
  • shell
June 10th, 2013
Scroll the current line to the top of the window in Vim
  • vim
May 13th, 2013
Double-click a surround in Terminal to select the matching symbol
  • shell
  • tools
April 16th, 2013
rake prereqs
  • ruby
April 8th, 2013
Put set -e in bash scripts to exit on error
  • shell
April 1st, 2013
Convert Github issues to pull-requests using hub
  • git
  • tools
January 16th, 2013
Create an ackrc file
  • shell
  • tools
December 20th, 2012
Ruby methods are implicit exception blocks
  • ruby
December 18th, 2012
Use vagrant-hostmaster to automatically update /etc/hosts
  • tools
December 3rd, 2012
Use * in Vim to find the next occurrence
  • vim
November 19th, 2012
Use vim-ruby-refactoring to quickly perform common refactorings
  • ruby
  • vim
November 13th, 2012
Ruby 2.0.0 keyword arguments
  • ruby
November 5th, 2012
Use %r for Ruby regular expressions
  • ruby
November 1st, 2012
Use :wa to save all open buffers in Vim
  • vim
October 31st, 2012
Forward ports without touching your router
  • tools
October 29th, 2012
git commit -v shows you the currently staged diff in your editor
  • git
October 25th, 2012
Install gist-vim to quickly share code snippets
  • git
  • vim
October 24th, 2012
Grab the last argument from the last command
  • shell
October 23rd, 2012
Use Shush to enable Push-to-talk for Skype meetings
  • tools
October 17th, 2012
Get a temporary directory in Ruby
  • ruby
October 17th, 2012
Redraw your VIM screen with Ctrl+L
  • shell
  • vim
October 16th, 2012
Use python -m SimpleHTTPServer to start a static web server
  • shell
October 12th, 2012
Ctrl+T shows you what your terminal is doing
  • shell
October 11th, 2012
Using source :rubygems in your Gemfile
  • ruby
October 9th, 2012
TeamViewer is great for remote pairing
  • tools
October 4th, 2012
Search all files with ack -a
  • shell
  • tools
October 4th, 2012
Validate/format JSON by piping to python -m json.tool
  • shell
October 3rd, 2012
Manage VIM packages with Vundle
  • vim
October 3rd, 2012
Avoid doing :set nopaste in VIM by using :r!cat
  • vim
October 2nd, 2012
Use Ctrl+R to fuzzy search bash history
  • shell
October 2nd, 2012
mkdir -p creates intermediate directories
  • shell
October 2nd, 2012