>> https://github.com/rails/rails/blob/353b88135f14a928352d4cf2f5f8e4ddacbd9d4a/activerecord/lib/active_record/schema_dumper.rb#L110
>>
>> + in lines 113 and 114
>>
>> he returns a value, then types 'nil'. Why is that? If the value is not returned isn't nil or error anyway?
>
> Regarding the return and the nil, the return contains an if clause. So
> it will only actually return if the @connection.respond_to? method
> returns true. Otherwise, the return will not be executed, and the next
> line is evaluated. A method returns the result of the last expression,
> and in this case, if the code reaches that line, the last expression
> will evaluate to nil, and that's what the method will return.


Yeah, but...

  return @connection.primary_key(table) if @connection.respond_to?(:primary_key)
  nil
end

is the same as

 if @connection.respond_to?(:primary_key)
  return @connection.primary_key(table)
 end
 nil

but "if" evaluates to nil if the condition is false...

 if @connection.respond_to?(:primary_key)
   return @connection.primary_key(table)
 else
   nil
 end
 nil

So that final nil is redundant. And so is the "return".

 - A


-- 
Alex Chaffee - alex / stinky.com
http://alexchaffee.com
http://codelikethis.com
http://twitter.com/alexch