Null object: Difference between revisions

Line 1,004:
=={{header|Ruby}}==
The value when referring to the instance variable which isn't initialized is nil.
<lang ruby>puts "@object is nil" if @object.nil?</lang> # instance variable
 
puts "$object is nil" if $object.nil? # global variable, too
 
# It recognizes as the local variable even if it isn't executed.
object = 1 if false
puts "object is nil" if object.nil?</lang>
{{out}}
<pre>
@object is nil
$object is nil
object is nil
</pre>
 
Anonymous user