Module: NoException

Defined in:
lib/noexception.rb

Constant Summary collapse

No =
self.No()
Go =
Go()

Class Method Summary collapse

Class Method Details

.Go(*methods) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/noexception.rb', line 25

def self.Go(*methods)
  Module.new do
    define_singleton_method(:included) do |klass|
      methods = klass.instance_methods(false) if methods.empty?
      mod = Module.new do
        methods.each do |m|
          define_method m do |*args|
            begin
              return super(*args), nil
            rescue StandardError => e
              return nil, e
            end
          end
        end
      end
      klass.prepend mod
    end
  end
end

.No(*methods) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/noexception.rb', line 2

def self.No(*methods)
  Module.new do
    define_singleton_method(:included) do |klass|
      methods = klass.instance_methods(false) if methods.empty?
      mod = Module.new do
        methods.each do |m|
          define_method m do |*args|
            begin
              return super(*args)
            rescue StandardError => e
              $error = e
              return nil
            end
          end
        end
      end
      klass.prepend mod
    end
  end
end