RubyGems Navigation menu

ignore_nil 1.0.3

The plugin is really rather simple; here's the ignore_nil method: def ignore_nil(&block) begin yield rescue NoMethodError, RuntimeError => e if (e.message =~ /You have a nil object when you didn't expect it/) || (e.message =~ /undefined method `.*?' for nil:NilClass/) || (e.message =~ /^Called id for nil/) return nil else raise e end end end What's interesting about this is it catches both NoMethodError and RuntimeError, both of which can occur if a method unexpectedly returned nil and you called a method on it, but *ONLY* if the error message matches! This means legitimate NoMethodError and RuntimeError messages will not be bothered by ignore_nil, and will still raise in your application as you expect. I've used this in a production application since about mid/late 2008, I'd consider it very stable. Feedback welcome!

Gemfile:
= Copier Copié!

installation:
=

Versions:

  1. 1.0.3 - October 16, 2009 (7 ko)

Propriétaires:

Auteurs:

  • Steven Soroka

Total de contrôle SHA 256:

6a0d5e17f74c3b0b857d3c03fb34a22cdafb1e338b23ff409576fde0c61daf7c

Total de téléchargements 7 935

Pour cette version 7 935

License:

aucune

Version de Ruby requise: None

Liens: