Skip to content

Instantly share code, notes, and snippets.

@ilake
Created November 13, 2012 23:16
Show Gist options
  • Select an option

  • Save ilake/4069075 to your computer and use it in GitHub Desktop.

Select an option

Save ilake/4069075 to your computer and use it in GitHub Desktop.
LEVEL 4: ACTIVESUPPORT
array.from(4)
array.to(2)
array.in_groups_of(3)
array.split(2)
array.index('word')
apocalypse = DateTime.new(2012, 12, 21, 14, 27, 45)
apocalypse.advance(years: 4, months: 3, weeks: 2, days: 1)
apocalypse.tomorrow
apocalypse.yesterday
options = {user: 'codeschool', lang: 'fr'}
new_options = {user: 'codeschool', lang: 'fr', password: 'dunno'}
options.diff(new_options) # {:password=>"dunno"}
options.stringify_keys # {"user"=>"codeschool", "lang"=>"fr"}
defaults = {:lang => 'en', :country => 'us'}
options = {:lang => 'fr', :user => 'codeschool'}
options.merge(defaults) #=> {:user=>"codeschool", :lang=>"en", :country=>"us"}
options.reverse_merge(defaults) #=> {:user=>"codeschool", :lang=>"fr", :country=>"us"}
new_options = {user: 'codeschool', lang: 'fr', password: 'dunno'}
new_options.except(:password) # {:user=>"codeschool", :lang=>"fr"}
new_options.assert_valid_keys(:user, :lang) # Unknown key(s): password (ArgumentError) throws an exception if the hash contains any keys besides those listed here
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment