Saturday, April 29, 2017

How to Code in Ruby on rails

How to Code in Ruby on rails


How to Code in Ruby on rails


What to program but dont know what language to start in? Ruby is perfect. In this selection, I will show you how to install ruby and show you how to get your first program up and running.

1.Installing Ruby

2.Before anything we need to install ruby. Go to rubys download site here http://rubyinstaller.org/downloads/ 

3.Download the latest version of ruby or the recommended version.

4.After downloading. Install the package.

5.Choosing a text editor and Basic syntax

6.Once you have installed ruby on your computer, now you a text editor or something to program ruby in.

7.Choosing a text editor would recommend downloading and installing one of these
  • Notepad++
  • Sublime Text
  • Vim
  • Atom
  • Emacs
8.After you have chosen a text editor its time to write your first program

9.We will start off by with some simple syntax for our program

10.First and most importantly. How to display text with code. You can do this with puts or print. Print and Puts are two different ways to display text. Puts is for if you want to write something and have basically pressing enter after is. Print is like writing something and then putting a space next to it.

11.Next the second most important piece of syntax. How to get input from a user and how to save it into a string/ variable. You can ask for input with get.chomp this asks for user-input. You save input by making the chomp equal to a variable.
  • In this dimenstration we will use x as the variable below

12.Also another piece of syntax includes gets, which is the equivalent to a pause without text in batch programming or if basicly just something that makes the program stop and continue when a any key is pressed.

13.Piecing the basic syntax together

14.For our first program we are going to just ask for there name and say it back to them.

15.Lets start of by asking them with there name. So eathier put puts or print then after that put (1) quotation mark then the question. Like this
  • puts "Hello, what is your name?"
  • print "Hello, what is your name?"

16.After you have asked them for there name, you ask for input and save it to a variable. Like this.
  • gets.chomp = fnamevar

17.Once you have asked your question and got user-input saved to a variable. Next what you want to do is read back there data. You do this by first putting your start-of text and then call for the variable and add them together. You do it like this. (In the code provided we added a new piece of ruby syntax. Which is #{}. This is how you call for a variable while displaying text.)
  • puts "Hello, #{fnamevar}
18.Saving and Running the program

19.Once you have installed ruby and wrote your first script. Now it is time to save and run the script. You can achieve this by clicking the file within your text editor and pressing save.

20.Once you have clicked save, name it what, save it where you want, and save it as a .rb on your file types.



21.Now run your ruby script. Congratulations you have just wrote your first ruby program.

Available link for download