matju writes:
> 	a .when_nil { b }

This sounds like good name. How about generalizing a little and having

  module Kernel
    def when(value, default=nil)
      if self == value
        if iterator?
          yield
        else
          default
        end
      else
        self
      end
    end
  end

  def first_way(a,b)
    b.detect {|i| a == i }.when nil, 0
  end

  for a in (1..3)
    b = [1,2]
    p first_way(a,b)
    p b.detect {|i| a == i}.when(nil) { 0 }  # second way
  end

Outputting:

1
1
2
2
0
0

	- Aleksi