Slide 1

Slide 1 text

5 random ruby tips Ruby SG Meetup (Jan 2013) by Huiming (@teohm)

Slide 2

Slide 2 text

Rails: remove database.yml ● In latest Rails 4 ● you can remove database.yml ● and use ENV[‘DATABASE_URL’] ● works in ActiveRecord, rails dbconsole, rake db:*

Slide 3

Slide 3 text

Rails: rails-assets.org (beta) ● Auto re-package Bower packages (and deps too!) into Ruby gems. ● Auto convert Sass & CSS assets helpers *-url() ○ currently supports image & font. # Gemfile source ‘https://rubygems.org’ source ‘https://rails-assets.org’ gem ‘rails-assets-bower_package’

Slide 4

Slide 4 text

Rails: non-js/css in assets pipeline ● In Rails 4, by default, only non-js/css files under app/assets/ are included. ● To include fonts under vendor/assets/fonts/: # config/environments/production.rb config.assets.precompile << lambda do |filename, path| path =~ /vendor\/assets/ && !%w(.js .css).include?(File.extname(filename)) end

Slide 5

Slide 5 text

Ruby: built-in conversion protocol Implicit conversion e.g. #to_str ● called by Ruby core classes when expect to get a String. Explicit conversion e.g. #to_s ● called by you to explicitly convert from a different type to String. Read more in “Confident Ruby” by Avdi Grimm http://www.confidentruby.com/

Slide 6

Slide 6 text

Shell: useful ag options ag -Q .empty? -G \\.haml$ ● faster than ack, better than grep ● search in current dir and sub dirs ● for literal text (-Q) .empty? ● limit to filenames (-G) ends with .haml Read more in “Conquering the Command Line” by Mark Bates http://conqueringthecommandline.com/