Upgrade to Pro — share decks privately, control downloads, hide ads and more …

RubySG 2014 Jan - 5 Random Ruby Tips

Huiming Teo
January 21, 2014

RubySG 2014 Jan - 5 Random Ruby Tips

Huiming Teo

January 21, 2014
Tweet

More Decks by Huiming Teo

Other Decks in Technology

Transcript

  1. 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:*
  2. 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’
  3. 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
  4. 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/
  5. 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/