Sha256: 1e0fde0e461ca6ded8f8d39e4ecd1be4cdc7f9473eac04c56d743ccb4056966f

Contents?: true

Size: 839 Bytes

Versions: 118

Compression:

Stored size: 839 Bytes

Contents

require 'tins'
$:.unshift 'examples'

include Tins::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

118 entries across 104 versions & 8 rubygems

Version Path
tdiary-5.2.4 vendor/bundle/ruby/3.1.0/gems/tins-1.31.1/examples/null_pattern.rb
tdiary-5.2.3 vendor/bundle/ruby/3.1.0/gems/tins-1.31.1/examples/null_pattern.rb
tdiary-5.2.2 vendor/bundle/ruby/3.1.0/gems/tins-1.31.1/examples/null_pattern.rb
tins-1.31.1 examples/null_pattern.rb
tdiary-5.2.1 vendor/bundle/ruby/3.1.0/gems/tins-1.31.0/examples/null_pattern.rb
tins-1.31.0 examples/null_pattern.rb
tins-1.30.0 examples/null_pattern.rb
tdiary-5.2.0 vendor/bundle/ruby/3.0.0/gems/tins-1.29.1/examples/null_pattern.rb
tdiary-5.2.0 vendor/bundle/ruby/2.7.0/gems/tins-1.29.1/examples/null_pattern.rb
tdiary-5.1.7 vendor/bundle/ruby/2.7.0/gems/tins-1.29.1/examples/null_pattern.rb
tdiary-5.1.7 vendor/bundle/ruby/3.0.0/gems/tins-1.29.1/examples/null_pattern.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/tdiary-5.1.5/vendor/bundle/ruby/2.7.0/gems/tins-1.28.0/examples/null_pattern.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/tdiary-5.1.5/vendor/bundle/ruby/3.0.0/gems/tdiary-5.1.4/vendor/bundle/ruby/2.7.0/gems/tins-1.26.0/examples/null_pattern.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/tdiary-5.1.5/vendor/bundle/ruby/3.0.0/gems/tins-1.26.0/examples/null_pattern.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/tins-1.29.1/examples/null_pattern.rb
tdiary-5.1.6 vendor/bundle/ruby/3.0.0/gems/tins-1.29.1/examples/null_pattern.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/tins-1.28.0/examples/null_pattern.rb
tins-1.29.1 examples/null_pattern.rb
tins-1.29.0 examples/null_pattern.rb
tdiary-5.1.5 vendor/bundle/ruby/3.0.0/gems/tdiary-5.1.4/vendor/bundle/ruby/2.7.0/gems/tins-1.26.0/examples/null_pattern.rb