Sha256: 88949652fea6d1fa2e22733e0a77554015f2c33e2bb995e1f626080c9d0f4566

Contents?: true

Size: 850 Bytes

Versions: 14

Compression:

Stored size: 850 Bytes

Contents

require 'dslkit/polite'
$:.unshift 'examples'

include DSLKit::Deflect

puts "Example 1"
deflect(NilClass, :method_missing, Deflector.new { nil }) do
  begin
    p "foo".bar.baz
  rescue NoMethodError
    p "caught 1"
  end
  p nil.bar.baz
  t = Thread.new do
    begin
      p nil.bar.baz
    rescue NoMethodError
      p "caught 2"
    end
  end
  t.join if t.alive?
  p nil.bar.baz
end
begin
  p nil.bar.baz
rescue NoMethodError
  p "caught 3"
end

puts "-" * 70, "Example 2"
deflect_start(NilClass, :method_missing, Deflector.new { nil })
begin
  p "foo".bar.baz
rescue NoMethodError
  p "caught 1"
end
p nil.bar.baz
t = Thread.new do
  begin
    p nil.bar.baz
  rescue NoMethodError
    p "caught 2"
  end
end
t.join if t.alive?
p nil.bar.baz
deflect_stop(NilClass, :method_missing)
begin
  p nil.bar.baz
rescue NoMethodError
  p "caught 3"
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
dslkit-0.2.13 examples/null_pattern.rb
dslkit-0.2.12 examples/null_pattern.rb
dslkit-0.2.11 examples/null_pattern.rb
dslkit-0.2.10 examples/null_pattern.rb
dslkit-0.2.9 examples/null_pattern.rb
dslkit-0.2.8 examples/null_pattern.rb
dslkit-0.2.7 examples/null_pattern.rb
dslkit-0.2.6 examples/null_pattern.rb
dslkit-0.2.2 examples/null_pattern.rb
dslkit-0.2.1 examples/null_pattern.rb
dslkit-0.2.0 examples/null_pattern.rb
dslkit-0.2.3 examples/null_pattern.rb
dslkit-0.2.4 examples/null_pattern.rb
dslkit-0.2.5 examples/null_pattern.rb