Null object: Difference between revisions
Content added Content deleted
Line 1,004: | Line 1,004: | ||
=={{header|Ruby}}== |
=={{header|Ruby}}== |
||
The value when referring to the instance variable which isn't initialized is nil. |
The value when referring to the instance variable which isn't initialized is nil. |
||
<lang ruby>puts "@object is nil" if @object.nil? |
<lang ruby>puts "@object is nil" if @object.nil? # 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}} |
{{out}} |
||
<pre> |
<pre> |
||
@object is nil |
@object is nil |
||
$object is nil |
|||
object is nil |
|||
</pre> |
</pre> |
||