Gavin Kistner
11/13/2006 10:21:00 PM
From: Comfort Eagle
> Why does this work:
...
> puts soup.a
...
> but adding .string a la:
...
> puts soup.a.string
...
> results in:
> undefined method `string' for nil:NilClass (NoMethodError) ??
This means that the return value of "soup.a" is nil. Nil is an object in
Ruby, so:
puts nil
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
actually meant:
puts soup.a.to_s
?