SlideShare a Scribd company logo
1 of 13
The Ruby Programming Language
Object Orientation
 Ruby is fully object oriented; everything is an object.
 Inheritance is shown by ‘<‘ instead of ‘extends’.
 Java: class Student extends Person
 Ruby: class Student < Person
 Modules are used to group classes
 class Person < ActiveRecord:: Base
 Modules are like namespaces in html and xml.
 Access controls are similar to Java: public, protected
and private. Each controls everything following it in
a class.
 All variables are accessed by reference.
Variables and Symbols
 Ruby is weakly typed. Variables receive their types
during assignment.
 There is no boolean type, but everything has a
value. False and nil are false and all other objects
are true.
 Instance variables (class variables) begin with the
‘@’ sign.
 @name, @age, @course
 Global variables begin with two ‘@’ signs. They are
almost never used.
 Symbols seem to be peculiar to Ruby. They begin
with a colon.
 :name, :age, :course
Blocks
 If a block consists of a single line, it is enclosed in
curly braces.
 Usually blocks begin with a control statement and
are terminated with the keyword, ‘end’.
 Indentation, usually two spaces, is used to indicate
what is in the block. Common errors are to have
either too few or too many ‘ends’.
 Variables within a block are local to the block unless
they are instance variables starting with the ‘@’ sign.
 Methods begin with the keyword, ‘def’, and are
terminated with an ‘end’.
 Parameters are enclosed with parentheses. If a
method has no parameters, the parentheses are
optional.
Basic Example Program – Java
public class People
{ public static void main (String [] args)
{ Person girl = new Person ("Alice", 5);
girl.show_person ();
}
} // People
class Person
{ String name;
int age;
Person (String name, int age)
{ this.name = name;
this.age = age;
}
protected void show_person ()
{ System.out.println (name);
System.out.println (age);
}
} // Person
Basic Example Program - Ruby
class Person
attr_accessor :name, :age
# initialize is the same as a constructor
def initialize (name, age)
@name = name
@age = age
end
# puts is the same as println
# print is the same as print
def show_person
puts @name
puts @age
end
end
girl = Person.new("Alice", 5)
girl.show_person
Instantiation and Initialization
 Ruby has girl = Person.new(“Alice”, 5).
 Java has Person girl = new Person(“Alice”,5);
 Java comments begin with ‘//’; Ruby’s with ‘#’.
 In Ruby we can write
 attr_accessor :name, :age
instead of getters and setters.
 String getName () { }
 void setName (String name) { }
Data Structures
 Arrays
 Indexed with integers starting at 0.
 Contents do not have to all be the same type.
 Contents can be assigned in a list using square
brackets.
 order = [“blue”, 6, 24.95]
 Arrays are objects so must be instantiated with ‘new’.
 Hash Tables
 Key – value pairs
 Keys are almost always symbols
 Contents can be assigned in a list of key-value pairs
using curly braces.
 order = {:color => “blue”, :size => 6, :price => 24.95}
 To retrieve an element, use square brackets
 @size = order[:size]
Control Structures: Conditionals
if order[:color] == “blue”
…
elsif order[:size] == 6
…
else
…
end
Control Structures: Iteration
 for, while and until
for item in order do
puts item
 Iterator ‘each’
sum = 0
[1..10].each do |count|
sum += count
end
puts sum
 count is a parameter to the block and has no value
outside of it.
Exceptions
begin
…
rescue
…
rescue
…
ensure
…
end
 rescue and ensure are the same as catch and finally
 Ruby also has throw and catch, similar to Java
Conventions
 Class names begin with upper case letters.
 Method and variable names use lower case.
 For names with more than one word:
 Class names use camel (or bumpy) case
 class ActiveRecord
 Method and variable names separate words with
underscores.
 def show_person
 @little_girl
 In Rails, table names are the plurals of the record
names
 Single record is course
 Table is called courses
 But the model class is called Course.
we provide online and classroom training for Ruby
Programming Language
For More Details
www.asit.amcsquare.com
Wise Machines India Pvt Ltd
#360, Sri Sai Padma Arcade,
Varthur Main Road,
Ramagondanahalli,
Whitefiled ,Bangalore – 560066.
We also having Branches in Hyderabad & Chennai

More Related Content

More from ASIT

ASIT EDUCATION STUDENT REVIEWS
ASIT EDUCATION STUDENT REVIEWSASIT EDUCATION STUDENT REVIEWS
ASIT EDUCATION STUDENT REVIEWSASIT
 
Asit Education
Asit EducationAsit Education
Asit EducationASIT
 
Asit Education Student Reviews
Asit Education Student ReviewsAsit Education Student Reviews
Asit Education Student ReviewsASIT
 
Asit education Student review
Asit education Student reviewAsit education Student review
Asit education Student reviewASIT
 
ASIT EDUCATION REVIEW
ASIT EDUCATION REVIEWASIT EDUCATION REVIEW
ASIT EDUCATION REVIEWASIT
 
Asit Never Cheats Unemployes
Asit Never Cheats UnemployesAsit Never Cheats Unemployes
Asit Never Cheats UnemployesASIT
 
Latest News on Amc Square Asit
Latest News on Amc Square AsitLatest News on Amc Square Asit
Latest News on Amc Square AsitASIT
 
Asit amc never cheats students
Asit amc never cheats studentsAsit amc never cheats students
Asit amc never cheats studentsASIT
 
News on AMC Square ASIT
News on AMC Square ASITNews on AMC Square ASIT
News on AMC Square ASITASIT
 
News on Asit Amc
News on Asit AmcNews on Asit Amc
News on Asit AmcASIT
 
Time Management
Time ManagementTime Management
Time ManagementASIT
 
learn Ruby at ASIT
learn Ruby at ASITlearn Ruby at ASIT
learn Ruby at ASITASIT
 
introduction to Mongodb
introduction to Mongodbintroduction to Mongodb
introduction to MongodbASIT
 
introduction to hadoop
introduction to hadoopintroduction to hadoop
introduction to hadoopASIT
 
ASIT REVIEWS
ASIT REVIEWSASIT REVIEWS
ASIT REVIEWSASIT
 
ASIT REVIEWS
ASIT REVIEWSASIT REVIEWS
ASIT REVIEWSASIT
 
Learn REST API at ASIT
Learn REST API at ASITLearn REST API at ASIT
Learn REST API at ASITASIT
 
Learn C LANGUAGE at ASIT
Learn C LANGUAGE at ASITLearn C LANGUAGE at ASIT
Learn C LANGUAGE at ASITASIT
 
Learn Advanced JAVA at ASIT
Learn Advanced JAVA at ASITLearn Advanced JAVA at ASIT
Learn Advanced JAVA at ASITASIT
 
Learn WCF at ASIT
Learn  WCF at ASITLearn  WCF at ASIT
Learn WCF at ASITASIT
 

More from ASIT (20)

ASIT EDUCATION STUDENT REVIEWS
ASIT EDUCATION STUDENT REVIEWSASIT EDUCATION STUDENT REVIEWS
ASIT EDUCATION STUDENT REVIEWS
 
Asit Education
Asit EducationAsit Education
Asit Education
 
Asit Education Student Reviews
Asit Education Student ReviewsAsit Education Student Reviews
Asit Education Student Reviews
 
Asit education Student review
Asit education Student reviewAsit education Student review
Asit education Student review
 
ASIT EDUCATION REVIEW
ASIT EDUCATION REVIEWASIT EDUCATION REVIEW
ASIT EDUCATION REVIEW
 
Asit Never Cheats Unemployes
Asit Never Cheats UnemployesAsit Never Cheats Unemployes
Asit Never Cheats Unemployes
 
Latest News on Amc Square Asit
Latest News on Amc Square AsitLatest News on Amc Square Asit
Latest News on Amc Square Asit
 
Asit amc never cheats students
Asit amc never cheats studentsAsit amc never cheats students
Asit amc never cheats students
 
News on AMC Square ASIT
News on AMC Square ASITNews on AMC Square ASIT
News on AMC Square ASIT
 
News on Asit Amc
News on Asit AmcNews on Asit Amc
News on Asit Amc
 
Time Management
Time ManagementTime Management
Time Management
 
learn Ruby at ASIT
learn Ruby at ASITlearn Ruby at ASIT
learn Ruby at ASIT
 
introduction to Mongodb
introduction to Mongodbintroduction to Mongodb
introduction to Mongodb
 
introduction to hadoop
introduction to hadoopintroduction to hadoop
introduction to hadoop
 
ASIT REVIEWS
ASIT REVIEWSASIT REVIEWS
ASIT REVIEWS
 
ASIT REVIEWS
ASIT REVIEWSASIT REVIEWS
ASIT REVIEWS
 
Learn REST API at ASIT
Learn REST API at ASITLearn REST API at ASIT
Learn REST API at ASIT
 
Learn C LANGUAGE at ASIT
Learn C LANGUAGE at ASITLearn C LANGUAGE at ASIT
Learn C LANGUAGE at ASIT
 
Learn Advanced JAVA at ASIT
Learn Advanced JAVA at ASITLearn Advanced JAVA at ASIT
Learn Advanced JAVA at ASIT
 
Learn WCF at ASIT
Learn  WCF at ASITLearn  WCF at ASIT
Learn WCF at ASIT
 

Recently uploaded

Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfSherif Taha
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docxPoojaSen20
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...Poonam Aher Patil
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxheathfieldcps1
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxVishalSingh1417
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...Nguyen Thanh Tu Collection
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.MaryamAhmad92
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfNirmal Dwivedi
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Third Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptxThird Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptxAmita Gupta
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 

Recently uploaded (20)

Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
Asian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptxAsian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptx
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Third Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptxThird Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptx
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 

Learn RUBY Programming Language at ASIT

  • 2. Object Orientation  Ruby is fully object oriented; everything is an object.  Inheritance is shown by ‘<‘ instead of ‘extends’.  Java: class Student extends Person  Ruby: class Student < Person  Modules are used to group classes  class Person < ActiveRecord:: Base  Modules are like namespaces in html and xml.  Access controls are similar to Java: public, protected and private. Each controls everything following it in a class.  All variables are accessed by reference.
  • 3. Variables and Symbols  Ruby is weakly typed. Variables receive their types during assignment.  There is no boolean type, but everything has a value. False and nil are false and all other objects are true.  Instance variables (class variables) begin with the ‘@’ sign.  @name, @age, @course  Global variables begin with two ‘@’ signs. They are almost never used.  Symbols seem to be peculiar to Ruby. They begin with a colon.  :name, :age, :course
  • 4. Blocks  If a block consists of a single line, it is enclosed in curly braces.  Usually blocks begin with a control statement and are terminated with the keyword, ‘end’.  Indentation, usually two spaces, is used to indicate what is in the block. Common errors are to have either too few or too many ‘ends’.  Variables within a block are local to the block unless they are instance variables starting with the ‘@’ sign.  Methods begin with the keyword, ‘def’, and are terminated with an ‘end’.  Parameters are enclosed with parentheses. If a method has no parameters, the parentheses are optional.
  • 5. Basic Example Program – Java public class People { public static void main (String [] args) { Person girl = new Person ("Alice", 5); girl.show_person (); } } // People class Person { String name; int age; Person (String name, int age) { this.name = name; this.age = age; } protected void show_person () { System.out.println (name); System.out.println (age); } } // Person
  • 6. Basic Example Program - Ruby class Person attr_accessor :name, :age # initialize is the same as a constructor def initialize (name, age) @name = name @age = age end # puts is the same as println # print is the same as print def show_person puts @name puts @age end end girl = Person.new("Alice", 5) girl.show_person
  • 7. Instantiation and Initialization  Ruby has girl = Person.new(“Alice”, 5).  Java has Person girl = new Person(“Alice”,5);  Java comments begin with ‘//’; Ruby’s with ‘#’.  In Ruby we can write  attr_accessor :name, :age instead of getters and setters.  String getName () { }  void setName (String name) { }
  • 8. Data Structures  Arrays  Indexed with integers starting at 0.  Contents do not have to all be the same type.  Contents can be assigned in a list using square brackets.  order = [“blue”, 6, 24.95]  Arrays are objects so must be instantiated with ‘new’.  Hash Tables  Key – value pairs  Keys are almost always symbols  Contents can be assigned in a list of key-value pairs using curly braces.  order = {:color => “blue”, :size => 6, :price => 24.95}  To retrieve an element, use square brackets  @size = order[:size]
  • 9. Control Structures: Conditionals if order[:color] == “blue” … elsif order[:size] == 6 … else … end
  • 10. Control Structures: Iteration  for, while and until for item in order do puts item  Iterator ‘each’ sum = 0 [1..10].each do |count| sum += count end puts sum  count is a parameter to the block and has no value outside of it.
  • 11. Exceptions begin … rescue … rescue … ensure … end  rescue and ensure are the same as catch and finally  Ruby also has throw and catch, similar to Java
  • 12. Conventions  Class names begin with upper case letters.  Method and variable names use lower case.  For names with more than one word:  Class names use camel (or bumpy) case  class ActiveRecord  Method and variable names separate words with underscores.  def show_person  @little_girl  In Rails, table names are the plurals of the record names  Single record is course  Table is called courses  But the model class is called Course.
  • 13. we provide online and classroom training for Ruby Programming Language For More Details www.asit.amcsquare.com Wise Machines India Pvt Ltd #360, Sri Sai Padma Arcade, Varthur Main Road, Ramagondanahalli, Whitefiled ,Bangalore – 560066. We also having Branches in Hyderabad & Chennai