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

Active Support Secrets

Active Support Secrets

Presented as a lightning talk at Nickel City Ruby Conference 2013 on September 21, 2013.

Video is available at http://www.confreaks.com/videos/2852-nickelcityruby2013-lightning-talk-active-support-secrets

Prem Sichanugrist

September 21, 2013
Tweet

More Decks by Prem Sichanugrist

Other Decks in Programming

Transcript

  1. very_complex_sql  =  <<-­‐SQL    SELECT  *    FROM  posts  

     WHERE  state='published' SQL #  =>  "    SELECT  *\n    FROM  posts\n     WHERE  state='published'\n"
  2. very_complex_sql  =  <<-­‐SQL.squish    SELECT  *    FROM  posts  

     WHERE  state='published' SQL #  =>  "SELECT  *  FROM  posts  WHERE   state='published'"
  3. content  =  <<-­‐README    Hello        World! README

    #=>  "    Hello\n        World!\n"
  4. class  FancyHello    def  initialize(user)        if  should_say_hello_to?

     user            content  =  <<-­‐README                Hello                    World!            README        end    end end #=>  "                Hello\n                    World!\
  5. class  FancyHello    def  initialize(user)        if  should_say_hello_to?

     user            content  =  <<-­‐README Hello    World! README        end    end end #=>  "Hello\n    World!\n"
  6. Date.parse('2013-­‐09-­‐21') #=>  Sat,  21  Sep  2013 '2013-­‐09-­‐21'.to_date #=>  Sat,  21

     Sep  2013   DateTime.parse('2013-­‐09-­‐21  09:00:00') #=>  Sat,  21  Sep  2013  09:00:00  +0000 '2013-­‐09-­‐21  09:00:00'.to_datetime #=>  Sat,  21  Sep  2013  09:00:00  +0000   Time.parse('09:00:00') #=>  2013-­‐09-­‐21  09:00:00  -­‐0400 '09:00:00'.to_time #=>  2013-­‐09-­‐21  09:00:00  -­‐0400
  7. hash  =  {  foo:  'foo',  bar:  'bar'  } #=>  {:foo=>"foo",

     :bar=>"bar"} hash.transform_keys  {  |key|    key.to_s.capitalize  } #=>  {"Foo"=>"foo",  "Bar"=>"bar"}
  8. state  =  if  params[:state].present?    params[:state] end   country  =

     if  params[:country].present?    params[:country] end   region  =  state  ||  country  ||  'US'