hl

Sunday, 12 March 2017

Ruby Programming Language Tutorials Lec 05

Tutorial 5

Load code form other file

     In ruby to load code from other file we just is to type load and then write name of the file then it will load commands from the file .The extension of the file should be .rb . For example - we crete a file of  name rubyOrNotRuby.rb and in the file we write puts "Hello From rubyOrNotRuby2" and save it and execute it it will print Hello From rubyOrNotRuby2

In file rubyOrNotRuby2.rb                         Output        rubyOrNotRuby.rb             




Operators

   
     Let's study about some logical operators. In ruby there are 3 logical operators and or not

     And there is also some comparison operators like == != < > <= >=


Simple program on condition

     So let's make a program of checking age of a child if it is between 5 and 6 .He should be in kindergarten . If the age is between 7 and 13. He is in middle School.else .Stay at home so let's code it.
1. First of all make a age variable and give the the value 13
2. Make a condition if(age>=5)&&(age<=6)
3. Write you're in kindergarten puts "you are in kindergarten"
4. Make another condition elseif (age>=7)&&(age<=13)
5. Write you're in Middle school puts "you're in Middle school "
6. Write Yeah puts "Yeah"
7. else
8. Write Stay Home puts "Stay Home"
9. end
end is must in if condition

                     Input                                                                 Output











Ruby Programming Language Tutorials Lec 04

Tutorial 4


Every thing is a class in ruby

     In ruby every thing is a class to see which thing is in which class just type puts for printing and followed by .class. For example for a number write 1.class for a float number write 1.234.class and for string "A string".class

                          Input                                                             Output



Constant 

     In ruby a constant is defining by staring it by a capital letter. For example: If we create a num by name A_CONSTANT and give it a value 31.4 and again change it by 1.6 it will show you the error but after that it will change the value also. Let us see :-


                          Input                                                             Output

 






File handling

     In ruby file handling is also so easy . Such as for creating a new file we is to type write_handeler = File.new for new file and passing 2 parameters in braces (name of file" yoursum.out " , type of operation "w") now the file is open .you can write into this file . For writing some text into it you is to write write_handler.puts("Random Text").to_s.After writting to it we is to close the file if the file is not closed it will continue to write to it .For closing the file type write_hander.close
      For read data from file there is a command data_from_file = File.read("yourSum.out") and printing it on screen write command puts "Data From File : " + data_from_file

                           Input                                                        Output


Saturday, 11 March 2017

Ruby Programming Language Tutorials Lec 03

Tutorial 3

Arithmetic operators :

     To work with the ruby on addition , substraction , multiplication , division and modulus is very simple so lets check it out-

Simply for addition write (6+4) it will work and so substraction , multiplication , division and modulus will also work the same 

                                 Input                                            Output

   










Limit of Integer

     In ruby the limit of the integer is so long it can take value more than 6,611,686,018,427,387,903
This is the longest integer limit till now.

Ruby uses different ways storing integers which allows you basically be able to store numbers
     
      Alright now I will show you some thing about float numbers.In ruby the floating point numbers are also so large  so for example lets make an float number "num_one = 1.0000"
and another float number " num99 = 0.999 " and command it puts num_one.to_s + " + " + num99.to_s + " = " + ( num_one - num99 ).to_s and running it  so lets check it out

Input



Output

It is so accurate upto very very end of its variable up to 20 digits

If we taking an integer big_float = 1.12345678901234 and command it to add the longest float so we can see that it can do calculation up to 14 digit of the decimals by commanding this puts (big_float + 0.00000000000005).to_s . It will show you 1.1234567890123899

                            Input                                                          Output


                                                                             










Wednesday, 8 March 2017

Ruby Programming Language Tutorials Lec 02

Tutorial 2


Print statement

       In ruby printing is done simply by typing print and forword by double quotes

                              Input                                                                  Output


Defining integers

     In ruby numbers are declared by simply typing their names such as if you want to take a no from name frist_num so type frist_num and after that your num is declared
 

And if you want to give it some value write " frist_num = 7 "

Taking inputs

     To take inputs from key board write puts and after an space put your integer there and followed by ".to_s"

Use of gets keyword

     Gets is a key word of ruby use to taking inputs 

Use of puts keyword

     Puts is a keyword of ruby use to putting value to integers

A Simple program in ruby of addition of two numbers

     To making a program of adding two numbers is also so eazy .Lets combine all we learned yet printing numbers, defining integers and taking inputs .So lets do it:

print "Enter a Value:"

frist_num = gets.to_i

print "Enter Another Value :"

second_num = gets.to_i

puts frist_num.to_s + " + " + second_num.to_s + " = " + (frist_num + second_num).to_s


Output :


Ruby Programming Language Tutorials Lec 01

Tutorial 1

  Starting with Ruby Programming language

     Hello every one welcome to my ruby programming tutorials. In this I am gonna cover pretty much 95% of basic ruby programming language all the basic syntax. Ruby is a basically a dynamic interpreted object oriented language. In which every thing is an object. Ruby is the one of the one of the easiest language to read and learn so firstly click here to go to the download page of ruby programming language. That is to be look like this
       *Choose your operating system here such as If you use windows choose windows. 
       *After downloading it install it. 
        





Single line comment

     In ruby single line comment is after # symbol every thing in that line is an comment.

                   Input                                                            Output                                      

                                                      

Multiline comment

     Multiline comment in ruby programming  is followed by =begain symbol after that every line is a comment while =end is not written in the file