Tuesday, March 31, 2015

Hands on ruby:Install,run,hello world

1.Install from Terminal
 sudo apt-get install ruby2.0 ruby2.0-dev 
2.How to run a program? There are two ways to do it.
 a.Interactive ruby shell Open your terminal(Ctrl+alt+t)
Type irb and hit enter.
Voila you can start typing your commands here
 b.Type all your commands and save it as filename.rb
 open your terminal ruby filename.rb
3.Every thing in ruby is an object including numbers
puts "Hello World"

puts "puts is like \n 1.printf in C \n 2. cin in C++ \n 3.System.out.print in java \n4.print in Python\n"

puts " # is a Single line comment"
=begin

This is multiline comment 
Every thing in between =begin and =end
is a multi line comment 

=end
languagge = "Ruby" #variable languagge has a value Ruby

puts "Hello #{languagge}" 

puts 4  #Number is an object in ruby
puts 4+4
puts 4.class
#puts 4.methods # Displays all methods that you can call on a number
Learn python for fun.The popular blog with questions and answers to the python.Solutions to facebookhackercup,codejam,codechef.The fun way to learn python with me.Building some cool apps.

No comments:

Post a Comment