Skip to content

Latest commit

 

History

History
36 lines (30 loc) · 878 Bytes

nil.md

File metadata and controls

36 lines (30 loc) · 878 Bytes

Jumpstart Live (JSL)

Day 5

nil

Overview

  • Everything in Ruby is an object (even nil is an object)
  • nil is the default value of many variables when they are first created and before you store something else in them
  • To check if something is nil you can use the nil? method

Examples

# everything is not automatically nil
# you do need to first declare it
puts x	# undefined local variable
nums = [1]
if nums[1].nil?
	puts "There is no value in index 1"
else 
	puts "#{nums[1]} is in index 1"
end

nums = [1, 2]
if nums[1].nil?
	puts "There is no value in index 1"
else 
	puts "#{nums[1]} is in index 1"
end

Resources