Skip to content

Instantly share code, notes, and snippets.

@wildjcrt
Created October 6, 2014 02:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wildjcrt/994dc210b8f957ae3477 to your computer and use it in GitHub Desktop.
Save wildjcrt/994dc210b8f957ae3477 to your computer and use it in GitHub Desktop.
>> a = [1, 2, 3, 4, 5, 1, 2]
=> [1, 2, 3, 4, 5, 1, 2]
>> a.compact.size
=> 5
>> a.compact!.size
NoMethodError: undefined method `size' for nil:NilClass
from (irb):14
from /Users/wildjcrt/.rvm/rubies/ruby-2.1.3/bin/irb:11:in `<main>'
>> hash=Hash.new []
=> {}
>> hash[:foo] << 1
=> [1]
>> hash[:foo] << 2
=> [1, 2]
>> hash[:foo] << 3
=> [1, 2, 3]
>> hash.each {|key, value| puts key; puts value;}
=> {}
>> hash
=> {}
>> hash.keys
=> []
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment