Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- irb(main):032:0> ratings = Hash.new(0)
- => {}
- irb(main):033:0> books.values.each { |rate| ratings[rate]+= 1 }
- => [:super, :super, :nul, :archi_nul]
- irb(main):034:0> ratings
- => {:super=>2, :nul=>1, :archi_nul=>1}
- irb(main):035:0> ratings = {}
- => {}
- irb(main):036:0> books.values.each { |rate| ratings[rate]+= 1 }
- NoMethodError: undefined method `+' for nil:NilClass
- from (irb):36:in `block in irb_binding'
- from (irb):36:in `each'
- from (irb):36
- from /usr/bin/irb:12:in `<main>'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement