Variable ruby

Estimated reading time: 1 minute

local variable

  • start with downcase or
  • underscore
name = "Mostafa Kamal"
_age = 54

Constant variable

  • start with Upcase
AgeKamal = 21

Parallel assign variables

name1, name2 = 'kamal', 'jamal'

symbol variables

instance variable

@insVar = 'This is instance variable'

class variable

  • class variable access from toplevel
@@classVar = "This is class variable"

global variable

$globalVar = "This is global variable"

psuedo variables

=begin
 self , true, false, nil, __FILE__, __LINE__
=end

access variables

puts name
puts "he is #{AgeKamal} and #{age}"

input from user

name = gets
name = gets.chomp

source

ruby