OmegaDev
Would you like to react to this message? Create an account in a few clicks or log in to continue.

IMP1 Ruby Tutorial

3 posters

Go down

IMP1 Ruby Tutorial Empty IMP1 Ruby Tutorial

Post by IMP1 Thu Jul 15, 2010 11:56 am

First off, download the Ruby Installer. It'll allow you to try out ruby by yourself.

Ruby Tutorial III - Variables

Things to know:
The puts method prints the following object as a string. Consider it to be short for 'Put Srting'.



Imagine a world where you could store a massive object (a number or a string and others not yet discorvered) in one word. Well, it's your lucky day. 'Cos that's excatly what a variable is.

One thing to remember, and that's that a variable starts with a lower-case letter, or an underscore.
Code:
my_first_variable = "The longest string in the whole wide world ever seen by a mortal other than that one mortal that saw that one string that time... but let's not go into that now, because it's a distraction from the main point, which is that this is a long string that nobody wants to type more than once."
Now whenever we use my_first_variable, we'll actually be using that string.

Input:
Code:
name = "IMP1"
puts "hi " + name + "."
Output:
Code:
"hi IMP1."
That's variables and strings, and it's pretty much the same with numbers.

Input:
Code:
variable1 = 10
variable2 = 1.5
puts variable1 * (variable2 + 1)
Output:
Code:
"25"
Variables can point to integers, floats, strings... Anything that isn't a variable. Let's see what happens if we try to point a variable to a variable.

Input:
Code:
a = 10
b = a
puts a
puts b
puts ''
a = 5
puts a
puts b
Output:
Code:
"10"
"10"

"5"
"10"
Notice how the b doesn't change. It's because when you assign it to a, it doesn't really become a, it becomes what a's pointing to.

Now, wasn't that easy? A short topic because there's so little to say about variable. They're just so darn simple.


Homework:
Practise, practise, practise.


Good Hunting.

NEXT TIME: Methods.


Last edited by IMP1 on Thu Jul 15, 2010 12:21 pm; edited 1 time in total
IMP1
IMP1
Coding Moderator
Coding Moderator

Posts : 503
Gald : 1399

Stats
Cookies: 5

Back to top Go down

IMP1 Ruby Tutorial Empty Re: IMP1 Ruby Tutorial

Post by omegas7 Thu Jul 15, 2010 12:05 pm

That is pretty good. I'm not good at explaining stuff but you make it pretty simple =D
omegas7
omegas7
Admin
Admin

Posts : 1180
Gald : 4121

Stats
Cookies: 0

http://www.omegadev.biz

Back to top Go down

IMP1 Ruby Tutorial Empty Re: IMP1 Ruby Tutorial

Post by crazedanimekid Thu Jul 15, 2010 1:52 pm

Pure Awesomeness IMP. Thanks for posting this.
crazedanimekid
crazedanimekid
Platinum Cookiez
Platinum Cookiez

Posts : 501
Gald : 1277

Stats
Cookies: 0

Back to top Go down

IMP1 Ruby Tutorial Empty Re: IMP1 Ruby Tutorial

Post by Sponsored content


Sponsored content


Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum