Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Variable Types in Ruby

  • class
  • type
  • Integer
  • Float
  • String
  • NilClass
  • TrueClass
  • FalseClass
  • Array
  • Hash

height = 187
puts height.class # Integer

weight = 87.3
puts weight.class # Float

text = "Some text"
puts text.class # String

empty = nil
puts empty.class # NilClass

debug = true
puts debug.class # TrueClass

debug = false
puts debug.class # FalseClass

names = ["Anna", "Bea", "Cecil", "David"]
puts names.class # Array

grades = {"math" => 99, "biology" => 87}
puts grades.class # Hash