When is nil not false?

James Byrne wrote:

Can someone see what I cannot given this code?

I need a return in front of the statement.

  def initialize(source=nil)     return xchg_source unless source     xchg_source(source)   end

James Byrne wrote:

James Byrne wrote:

Can someone see what I cannot given this code?

I need a return in front of the statement.

  def initialize(source=nil)     return xchg_source unless source     xchg_source(source)   end

Why not just let xchg_source deal with the nil then you just have:

def initialize(source=nil)   xchg_source(source) end

protected # assuming this is not part of the public interface def xchg_source(source)   if source     # whatever you do if source is given   else     # whatever should happen if source is nil   end end