Module: TryBlock
- Defined in:
- lib/dolzenko/try_block.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.install! ⇒ Object
2 3 4 5 6 7 |
# File 'lib/dolzenko/try_block.rb', line 2 def self.install! unless Object.include?(self) Object.send(:include, self) Object.send(:public, :try_block) end end |
Instance Method Details
#try_block(&block) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/dolzenko/try_block.rb', line 9 def try_block(&block) raise ArgumentError, "should be given block" unless block return if self.nil? caller_size = caller.size # JRuby reports this weird ":1" line in caller if RUBY_PLATFORM =~ /\bjava\b/ && caller[-1] == ":1" caller_size -= 1 end begin self.instance_eval(&block) rescue NoMethodError => e if e.backtrace.size - caller_size == 3 && e. =~ /^undefined method.+for nil:NilClass$/ return nil end raise end end |