T-3 until assessment00 window closes

Ruby Review

  • Core Ruby Classes Screencast
    • Strings
      • strip take off white space at beginning and end of string
      • %q{} or %q// for single quotes, %Q{} or %Q// for double quotes
    • Arrays
      • Array.new(num_of_elements, value_of_element) to create plain arrays, and Array (0..100) to create incremented arrays
      • %W// for interpolation in arrays
      • flatten if you have an array of arrays
      • traverse an array by index easier with each_index
      • There are at least two different ways to create an array with many equal elements
        • first = Array.new(100,"") will create an array of 100 elements pointing to the same empty string
        • second = Array.new(100){""} will create an array of 100 individual elements
        • The difference between these two becomes obvious when starting to append to the empty string with << , since, appending to any string in the first array will affect all other strings, while in the second, it will not
    • Hash
      • call constructor with Hash.new(0) so that the default value of the hash is not nil
    • Enumerable
      • find_all seems to be the same as select
      • 1.upto(100) is a more convenient version of (1..100).each , I guess.
      • Array and Hash implement enumberable
  • Cooper
    • RegEx
      • sub replaces the first pattern it finds, gsub replaces every pattern it finds
      • scan is a useful method for stings, like slice but finds every occurrence and makes an array
        • However cool… note a limitation: if sen = "so I found brie"
        • sen.scan(/([euioa]+)\w*/i)
          • returns: [["o"], ["I"], ["ou"], ["ie"]] 
        • [euioa]+ means 1 or more vowels
          • inside parentheses so that this is put into the output array, and has its own cell
        • \w* means 0 or more characters
        • the final outside the forward slashes means case insensitivity
        • Limitation: something like “fantastic” or “foundational” will only get the first few consecutive vowels captured
          • Solution: just scan by word: "foundational".scan(/[euioa]/) will pull all the vowels
            • if you wanted all consonants, add a carrot within the brackets: "foundational".scan(/[^euioa]/)
      • =~ is a matching operator: "dfg real fdg word".split.select{ |e| e =~ /[euioa]/ } returns => ["real", "word"] 
    • Hashes
      • each through a hash gives |key, value| to play with
    • Randomizing – rand(10) returns a number from 0..9
    • inspect gives a textual representation of an object:
      • nil.to_s returns ""
      • nil.inspect returns "nil"


  • Capybara built on top of Webrat
  • !! in the terminal will repeat the previous command
  • always prepare test database after migration
  • Heroku Screencast
    • heroku ps shows processes
    • heroku logs shows logs
    • heroku run for any command run remotely (like db migration), or heroku run console
    • how to get things onto heroku that you don’t want to commit to git?
      • environment variables: ENV['STORED_ELSEWHERE']
    • heroku apps shows apps
      • heroku destroy app_name (and then type again)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s