From: Comfort E.
Why does this work:
but adding .string a la:
undefined method `string’ for nil:NilClass (NoMethodError) ??
This means that the return value of “soup.a” is nil. Nil is an object in
passes a nil object to the ‘puts’ method. The ‘puts’ method calls the
‘to_s’ method on the argument(s) passed to it. Nil has a to_s method
(that returns an empty string), so all is well.
However, nil does not have a ‘string’ method, which is the error you are
getting. Perhaps you are confusing Ruby with another language, and