top of page
Search
  • Writer's pictureHox Framework

Ruby Basics - A little bit of everything tutorials || HOX FRAMEWORK

1. Download ruby : https://rubyinstaller.org/downloads/


2. In the ending of the installers process there will be a checkbox to run

" ridk install " to install MSYS2 and development toolchain. MSYS2 is

required to install gems with C extensions, make sure this checkbox is checked.


3.Then a popup will be opened in CMD and it will say RubyInstaller2,

it will offer you base installation,system update ,and MSYS2 and MINGW

development toolchain. It is recommended to go 1, 2 and then 3, in that order

to install absolutely everytihing you need.


4. You can run your programs trough terminal and switch later when you go

pro to something else. Just so you know- you can edit ruby code in any text editor.


CODE ONE:


print "Hello World"

print "is a nice way to start."

puts "Jeremy Clarkson" #after this we get a newline

puts "is getting old" #Does it put the newline in front or back? Guess.



puts "Welcome legend, what is your name?" #\n


name = gets.chomp


#print "Hello "+ name +" How are you?"


print "Hello "+ name +" How are you?"


CODE TWO:




somewords = "SS)J#DUNCTF{ThanksMan}INDSAIDKM"

puts "length:" ,somewords.length()

#so we dont use + here cause we cant add string to integer, instead

#we use ,

puts somewords[11,11]

# ^ try 21 see why it doesnt work




CODE THREE:


days = "The random number is : "

numbers = [1,2,3,4,5,6,7,8,9,0]

null = [0,1]

key = numbers[1].to_s

key2 = Array[rand(numbers.length)]

puts key2

key22 = key2.join(",")

puts days + key22



#DATA TYPES

#strings, integers, floats ,boolean and NULL values - nil

errors = nil

#that means flaws DOESNT have a value.


CODE FOUR:


def sayhi2(username)

puts ("Hello user:" + username)

end

sayhi2("HoxFramework")



#A (class)Hash is a dictionary-like collection of unique keys and their values.

#Also called associative arrays

#basically a dictionary:


people = {

"Luke" => "16",

"Tim" => "22",

"Jenny" => "24"

:admin => "22"

}

puts people["Luke"]

puts people["22"]

puts people[:admin]


CODE FIVE:

print "Enter a number:"

mynumber = gets.chomp()

puts(mynumber.to_i)

puts "Now its an integer, you may not see the difference, but computer does"





puts ""

food = Array["Burger","Kebab","Vodka"]


puts food.length()

puts "i need "

puts food[2]


CODE SIX:


#IF statements in ruby

def someFunction(entry)

puts "Do you wanna go?\n1.Yes\n2.No\n3.Patrick"

if entry == "1"

puts "Okay lets go"

return "dude"

elsif entry == "2"

puts "Alright dont yell at me"

else

return "Ah yes its Patrick"

end #why 2 ends?

end


puts someFunction("1")

puts someFunction(1)

puts someFunction("2)





2 views0 comments

Recent Posts

See All
bottom of page