ndhaniff
11/17/2017 - 6:43 PM

Ruby snippet

ruby cheatsheet

#method

def method(par)
  par = "hello world"
end

def method
  puts = "hello world"
end

#string

fname = "endy"
lname = "haniff"

puts = fname + lname

#string interpolation #{variable} not work in single quote

name = "endy haniff"

puts "My name is #{endy}"

#accessing method in common class
fname = "endy"
fname.length #outputting 4

#evaluate string
fname = "" 
fname.nil? #output false
fname.empty? #output true

#ask input
puts "Enter your first Name"

firstName = gets.chomp

puts "Welcome #{firstName}"

#array
fname = ["endy","haniff"]

#hash or associative arrays
fname = { "name" => "Endy", "color" => "red" }

#hash access with symbol
fname = { a => 1, b =>2 , c => 3}
fname[:c] #output 3

#oop class
class User
    
end

user = User.new #instantiate

puts user