My submission for Ruby Challenge #3: Short Circuit
rubylearning.com/blog/2009/10/30/rpcfn-short-circuit-3/
-
100% RSpec test coverage
-
Works in both Ruby 1.8 and 1.9
| # Newbie Programmer | |
| def factorial(x) | |
| if x == 0 | |
| return 1 | |
| else | |
| return x * factorial(x - 1) | |
| end | |
| end | |
| puts factorial(6) | |
| puts factorial(0) |
| # Drop this file in config/initializers to run your Rails project on Ruby 1.9. | |
| # This is three separate monkey patches -- see comments in code below for the source of each. | |
| # None of them are original to me, I just put them in one file for easily dropping into my Rails projects. | |
| # Also see original sources for pros and cons of each patch. Most notably, the MySQL patch just assumes | |
| # that everything in your database is stored as UTF-8. This was true for me, and there's a good chance it's | |
| # true for you too, in which case this is a quick, practical solution to get you up and running on Ruby 1.9. | |
| # | |
| # Andre Lewis 1/2010 | |
| # encoding: utf-8 |
| def tip(msg); puts; puts msg; puts "-"*100; end | |
| # | |
| # 30 Ruby 1.9 Tips, Tricks & Features: | |
| # http://www.igvita.com/2011/02/03/new-ruby-19-features-tips-tricks/ | |
| # | |
| tip "Upgrading to Ruby 1.9 is simple: rvm install 1.9.2 && rvm --default 1.9.2" | |
| tip "Ruby 1.9 supports named captures in regular expressions!" |
| # ====================================================================== | |
| # | |
| # @link http://wuhrr.wordpress.com/2010/01/13/adding-confirmation-to-bash/#comment-3540 | |
| # | |
| # Function: confirm | |
| # Asks the user to confirm an action, If the user does not answer "This won't shutdown the Internet!" the script will immediately exit. | |
| # | |
| # Parameters: | |
| # $@ - The confirmation message | |
| # |
| wfs = [["ac", nil], | |
| ["bk", | |
| [{"workflow_id"=>"image-generate-widths", "conditions"=>{"m"=>"and", "g"=>[{"file_type_in"=>["jpg", "JPG", "jpeg", "JPEG", "png", "PNG"]}]}}, | |
| {"workflow_id"=>"image-generate-marketplaces-bk", | |
| "conditions"=> | |
| {"m"=>"and", | |
| "g"=> | |
| [{"file_type_in"=>["jpg", "JPG", "jpeg", "JPEG", "png", "PNG"]}, | |
| {"filename_does_not_match"=>"M[0-9]{10}-[a-zA-Z]{1,3}[0-9]{0,2}?[a-zA-Z]?_[a-zA-Z]{2}.(jpg|JPG|png|PNG|gif|GIF|webm|WEBM|mp4|MP4|zip|ZIP)"}]}}, | |
| {"workflow_id"=>"video-transcoder", "conditions"=>{"m"=>"and", "g"=>[{"file_type_in"=>["mov", "MOV", "MP4", "mp4"]}]}}]], |