Wednesday, 22 June 2016

Ruby


1) Installation of Ruby 

http://rubyinstaller.org/


2) After installation-->in windows
  > Run cmd
 

3) To check the version

  > ruby -v


4)

Interactive Ruby (IRb):


Just type irb at your command prompt and an Interactive Ruby Session will start as given below:
$irb
irb 0.6.1(99/09/16)
irb(main):001:0> def hello
irb(main):002:1> out = "Hello World"
irb(main):003:1> puts out
irb(main):004:1> end
nil
irb(main):005:0> hello
Hello World
nil
irb(main):006:0>





---------------------------------------------------------------------------------------------------------------

Ruby Global Variables:  $

Global variables begin with $. Uninitialized global variables have the value nil

Ruby Instance Variables:  @ 


Instance variables begin with @

Ruby Class Variables:  @@


Class variables begin with @@ and must be initialized before they can be used in method definitions.
Referencing an uninitialized class variable produces an error.

------------------------------------------------------------------------------------------------------
class Student
   @@no_of_students=0
   def initialize(id,name,addr)
     @stu_id=id
     @stu_name=name
     @stud_add=addr
    end  

def display()
 puts "student  #@stud_id  #@stu_name  #@stud_add" 
end
end

stu1=Student.new("1","sree","IN")
stu2=Student.new("2","sahi","US")

stu1.display()
stu2.display()
-------------------------------------------------------------

> ruby sahi.rb



----------------------------------------------------------------------------------------------------------























No comments:

Post a Comment