I thought ==nil and .nil? would yield the same result.
Yes they are giving. Look my below example:
require 'csv'
c1 = CSV::Row.new(["h1","h2","h3"],[1,2,3])
# => #<CSV::Row "h1":1 "h2":2 "h3":3>
c2 = CSV::Row.new(["h1","h3","h4"],[1,2,3])
# => #<CSV::Row "h1":1 "h3":2 "h4":3>
[nil,c1,c2].delete_if { |x| x.nil? }
# => [#<CSV::Row "h1":1 "h2":2 "h3":3>, #<CSV::Row "h1":1 "h3":2 "h4":3>]
[nil,c1,c2].delete_if { |x| x==nil }
# => [#<CSV::Row "h1":1 "h2":2 "h3":3>, #<CSV::Row "h1":1 "h3":2 "h4":3>]
c1.respond_to?(:nil?) # => true
c1.respond_to?(:==) # => true
c1==nil # => false
c1.nil? # => false
Your code,which you suspect as an error,is perfect. But from the line '==': undefined method 'row' for nil:NilClass (NoMethodError)
, it is much clear that,you used some where else in your code something == something.row
, where that something
is nil
. Thus you got the error as NilClass
do not have any #row
method.