This is just a quick Question. I am writing a feature here that creates a hash that has the Developer name as key and amount of points he scores for each feature he completed summed together. but we do have lazy Developers that don’t assign themselves to a task and thus we get hashes with nil as a key and i get NoMethodError: undefined method `name’ for nil:NilClass. what would be a clean way of ignoring nil?? here is my code
feat_hash = {}
features.group_by {|dev| dev.developer.name}.each {|dev_id, feat| feat_hash[dev_id] = feat.inject(0){|sum, x| sum + x.points}}
thanks in advance! 😀
EDIT: cool so this is the output that i get when i run it. you will notice it renders through the sprints that have the features that are assigned and those that are empty but as soon as it gets into a hash with a unassigned feature with nil as key it bugs out.
_________features___________
{"Gary"=>13, "Rob"=>8, "Hannes"=>8, "Sandra"=>1}
___________bugs_____________
{}
__________chores____________
{}
*************** New Sprint ************************
_________features___________
{}
___________bugs_____________
{}
__________chores____________
{}
*************** New Sprint ************************
_________features___________
{}
___________bugs_____________
{}
__________chores____________
{}
*************** New Sprint ************************
NoMethodError: undefined method `name' for nil:NilClass
and then the rest of the error stack
You have this error because in the instruction
dev.developer.name,dev.developerisnil. You can ignore these devs before thegroup_by