Ruby Programming Tutorial - Lesson 02 - Constant values and Data types

in #ruby7 years ago (edited)

ruby.jpg

If you followed my previous lecture,
you should be ready to write some ruby programs now :)
Before we start ..
Download and install your favorite text editor software.
in my Case i am using Visual studio code.

print "Hello World"

Lets write our first ruby program now,
creating a new file, and saving it with .rb extension will create a ruby program for us.

its time to execute the code, to see if it works
we can execute a ruby program doing this.

ruby variable.rb

Constants

Now lets talk about constant values.
every number like, 1, 2, 3, 1.34, 1.09, 0.0000034, or -1.98 is a constant value.
it is called constant because it never changes..
like 2 is a constant value which always remains to be 2 :)

Similarly each alphabet characters are also constant values
like "a", "b" , "c" these are all constant values..
lets type some constant values. and see what we get when we execute our program

Variables

Variables are value holders basically, they hold constant values, but variables can be changed while constant values cannot be changed.

variable = 20
puts variable
variable = 100
puts variable

Variables are so lovely that they can hold values like Bitcoins :) .. variables hold STEEM, variables will hold any data
you want them to hold,
you can store earths inside of them :p

variable "Earth" like so and trust me it will hold the earth inside of it..

you can create as many variables as you want in your program, you can also give them different names of your own choice, you can be as creative as you can ... in naming them.

Magic has just begun :)
Here is some fun program that tells you how many girl friends I have, and how many bitcoins I have :D

Once you learn the magic, of writing variables. and store values in them.. you are open for anything and everything
Be creative and make many variables. and put inside of them some cool values..
Share with me in comments of what variables you created.. and what values you stored in them..

Note : I don't even have a single Girl friend :p ...

Sort:  

보팅부탁드려요~^^즐거운하루되세요♡♡

Thanks for your comment, but i cannot understand it :)

:D its funny .. she gave 2 hearts.. but i can't understand her comment :D