RubySG 2014 Jan - 5 Random Ruby Tips

RubySG 2014 Jan - 5 Random Ruby Tips

37ef5e5ddd4b05465000dbea5d4b22e2?s=128

Huiming Teo

January 21, 2014
Tweet

Transcript

  1. 5 random ruby tips Ruby SG Meetup (Jan 2013) by

    Huiming (@teohm)
  2. 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:*
  3. 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’
  4. 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
  5. 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/
  6. 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/