SlideShare une entreprise Scribd logo
1  sur  84
Télécharger pour lire hors ligne
FossConf'08




Ruby – An Introduction
          T.Shrinivasan
          tshrinivasan@gmail.com

          Indian Linux User Group, Chennai
Ruby is a Programming Language
There are so many 
Programming Languages.



     Why    Ruby?
Ruby is simple and beautiful
Ruby is Easy to Learn
Ruby is Free Open Source Software
Ruby on Rails – Web Framework
RAA
●   Ruby Application Archive
●   1648 projects



●   http://raa.ruby-lang.org
Rubyforge
●   5070 projects and libraries

●   http://rubyforge.org/
Can do
●
    Text Handling             ●
                                  Games
●
    System Administration     ●
                                  NLP
●
    GUI programming
●
    Web Applications          ●
                                  ...
●
    Database Apps
●
    Scientific Applications
History
Ruby
Yukihiro “Matz” Matsumoto
                      Japan
          February 24, 1993
 Perl  Java  Python  Ruby  PHP
1987       1991         1993  1995
        What is Ruby?
Ruby is…


          A dynamic, open source
programming language with a focus on
simplicity and productivity. It has an
elegant syntax that is natural to read
and easy to write.
Quick and Easy
●
         Intrepreted Scripting Language
●
         Variable declarations are unnecessary
●
         Variables are not typed
●
         syntax is simple and consistent
●
         memory management is automatic
Object Oriented Programming
●
         Everything is an object
●
         classes, methods, inheritance, etc.
●
         singleton methods
●
         quot;mixinquot; functionality by module
●
         iterators and closures
Examples!
5.times { print “Ruby! quot; }
5.times { print “Ruby! quot; }
Ruby! Ruby! Ruby! Ruby! Ruby!
Everything is
  an object
100.next
100.next
101
“I love Ruby” 
.reverse.capitalize
“I love Ruby” 
.reverse.capitalize

“Ybur evol i”
3.hours.from_now
3.hours.from_now

Thu Jan 19 22:05:00 Eastern   
Standard Time 2006
Conventions
Variables



colored_index_cards
Class Names



  Person
Symbols



:street_name
Instance Variables



 @school_name
Constants



Kilograms_Per_Pound
Input
puts “What is Your name?”

name = gets

name = name.chomp

puts quot;Helloquot; + name + quot; .Welcomequot;
            Flow
if ( score >= 5000 )
  puts “You win!”
elsif ( score <= 0 )
  puts “Game over.”
else
  puts “Current score: #{score}”
end
puts “PASS” if mark > 35
                    Loop
count = 0
5.times do
  count += 1
  puts quot;Count =quot; + count.to_s
end
Count   =   1
Count   =   2
Count   =   3
Count   =   4
Count   =   5
count = 0
while count < 10
  puts quot;Count = quot; +count.to_s
  count += 1
end
Blocks
1.upto(5) { |x| puts x }
1
2
3
4
5
5.downto(1) do |time|
  print “#{time}... ”
  puts “!” if time <= 3
end


5... 4... 3... !
2... !
1... !
Array
Array
numbers = [ quot;zeroquot;, quot;onequot;, quot;twoquot;,
 quot;threequot;, quot;fourquot; ]  
Array
numbers = [ quot;zeroquot;, quot;onequot;, quot;twoquot;,
 quot;threequot;, quot;fourquot; ]  


>> numbers[0]
=> quot;zeroquot;


>> numbers[4]
=> quot;fourquot;
Array
numbers = [ quot;zeroquot;, quot;onequot;, quot;twoquot;,
 quot;threequot;, quot;fourquot; ]


>> numbers[3].upcase
=> quot;THREEquot;
>> numbers[3].reverse
=> quot;eerhtquot;
Sort Array
primes = [ 11, 5, 7, 2, 13, 3 ]
Sort Array
primes = [ 11, 5, 7, 2, 13, 3 ]


primes.sort
Sort Array
primes = [ 11, 5, 7, 2, 13, 3 ]


primes.sort


=> [2, 3, 5, 7, 11, 13]
Sort Array
names = [ quot;Shriniquot;, quot;Balaquot;,
 quot;Sureshquot;, quot;Arulquot;]
Sort Array
names = [ quot;Shriniquot;, quot;Balaquot;,
 quot;Sureshquot;, quot;Arulquot;]


names.sort
Sort Array
names = [ quot;Shriniquot;, quot;Balaquot;,
 quot;Sureshquot;, quot;Arulquot;]


names.sort


=>[quot;Arulquot;, quot;Balaquot;, quot;Shriniquot;,
 quot;Sureshquot;]
More on Arrays
●
    Reverse
●
    Length
●
    Delete
●
    Join
●
    Find
●
    More than 100 methods
Hashes
menu = {
  :idly        =>   2.50,
  :dosai       =>   10.00,
  :coffee      =>   5.00,
  :ice_cream   =>   5.00
}

menu[:idly]
2.50
Methods
Methods

def say_hello(name)
  result = “Hello, #{name}!”
  return result
end
puts say_hello(“world”)
Methods

def say_hello(name)
  “Hello, #{name}!”
end
puts say_hello(“world”)
Class
Classes
class MathWhiz
  def say_square(value)
    puts value * value
  end
end
sam = MathWhiz.new
sam.say_square(5)
Inheritance
class Dog < Animal
  @catagory = “mammal”
  @legs     = 4
end
Module
Modules
module Trig
  PI = 3.141592654
  def Trig.sin(x)
    # ..
  end
  def Trig.cos(x)
    # ..
  end
end
Modules
require quot;trigquot;
y = Trig.sin(Trig::PI/4)
0.707106780551956
Attributes
class PlainOldRubyObject
  attr_accessor :food, :drinks
  attr_reader   :advice
  attr_writer   :write_only
end
Scope
class Poet
  #public by default
  def poetry
  end

  protected
  def family_legacy
  end

  private
  def hopes_and_dreams
  end
end
THE END
   of code :-)
How to Learn?
irb
●   interactive ruby
●   A ruby Shell
●   Instance response
●   learn as you type
Web sites




            Web Sites
http://ruby­lang.org




www.ruby­lang.org
www.rubyforge.net
http://www.ruby­forum.com/
Training Centers
Ruby User Groups

chennairb@googlegroups.com

●   Mailing List
●   Meetings
●   Tutorial Sessions


Join Today
We thank                         and                               for Photos




                            Copyright (c)  2008 
  Permission is granted to copy, distribute and/or modify this document
  under the terms of the GNU Free Documentation License, Version 1.2
      or any later version published by the Free Software Foundation.

                   http://www.gnu.org/copyleft/fdl.html
                                     

Contenu connexe

Tendances

Intro To Ror
Intro To RorIntro To Ror
Intro To Ror
myuser
 

Tendances (20)

Ruby programming
Ruby programmingRuby programming
Ruby programming
 
Ruby Presentation
Ruby Presentation Ruby Presentation
Ruby Presentation
 
Ruby Programming Introduction
Ruby Programming IntroductionRuby Programming Introduction
Ruby Programming Introduction
 
Ruby for Java Developers
Ruby for Java DevelopersRuby for Java Developers
Ruby for Java Developers
 
Add Perl to Your Toolbelt
Add Perl to Your ToolbeltAdd Perl to Your Toolbelt
Add Perl to Your Toolbelt
 
Why Ruby
Why RubyWhy Ruby
Why Ruby
 
Introduction to perl_ a scripting language
Introduction to perl_ a scripting languageIntroduction to perl_ a scripting language
Introduction to perl_ a scripting language
 
Intro To Ror
Intro To RorIntro To Ror
Intro To Ror
 
Introduction to Ruby
Introduction to RubyIntroduction to Ruby
Introduction to Ruby
 
Regular Expressions: Backtracking, and The Little Engine that Could(n't)?
Regular Expressions: Backtracking, and The Little Engine that Could(n't)?Regular Expressions: Backtracking, and The Little Engine that Could(n't)?
Regular Expressions: Backtracking, and The Little Engine that Could(n't)?
 
Ruby and rails - Advanced Training (Cybage)
Ruby and rails - Advanced Training (Cybage)Ruby and rails - Advanced Training (Cybage)
Ruby and rails - Advanced Training (Cybage)
 
Introduction to JavaScript
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScript
 
Ph pbasics
Ph pbasicsPh pbasics
Ph pbasics
 
Java script
Java scriptJava script
Java script
 
Lecture 5 javascript
Lecture 5 javascriptLecture 5 javascript
Lecture 5 javascript
 
SOLID Ruby, SOLID Rails
SOLID Ruby, SOLID RailsSOLID Ruby, SOLID Rails
SOLID Ruby, SOLID Rails
 
Learn Ruby 2011 - Session 5 - Looking for a Rescue
Learn Ruby 2011 - Session 5 - Looking for a RescueLearn Ruby 2011 - Session 5 - Looking for a Rescue
Learn Ruby 2011 - Session 5 - Looking for a Rescue
 
01 basics
01 basics01 basics
01 basics
 
php basic
php basicphp basic
php basic
 
Overview of CoffeeScript
Overview of CoffeeScriptOverview of CoffeeScript
Overview of CoffeeScript
 

Similaire à Ruby An Introduction

Similaire à Ruby An Introduction (20)

Arulalan Ruby An Intro
Arulalan  Ruby An IntroArulalan  Ruby An Intro
Arulalan Ruby An Intro
 
Ruby on Rails Presentation
Ruby on Rails PresentationRuby on Rails Presentation
Ruby on Rails Presentation
 
When To Use Ruby On Rails
When To Use Ruby On RailsWhen To Use Ruby On Rails
When To Use Ruby On Rails
 
Develop realtime web with Scala and Xitrum
Develop realtime web with Scala and XitrumDevelop realtime web with Scala and Xitrum
Develop realtime web with Scala and Xitrum
 
Ruby Hell Yeah
Ruby Hell YeahRuby Hell Yeah
Ruby Hell Yeah
 
Perl 101
Perl 101Perl 101
Perl 101
 
ppt7
ppt7ppt7
ppt7
 
ppt2
ppt2ppt2
ppt2
 
name name2 n
name name2 nname name2 n
name name2 n
 
name name2 n2
name name2 n2name name2 n2
name name2 n2
 
test ppt
test ppttest ppt
test ppt
 
name name2 n
name name2 nname name2 n
name name2 n
 
ppt21
ppt21ppt21
ppt21
 
name name2 n
name name2 nname name2 n
name name2 n
 
ppt17
ppt17ppt17
ppt17
 
ppt30
ppt30ppt30
ppt30
 
name name2 n2.ppt
name name2 n2.pptname name2 n2.ppt
name name2 n2.ppt
 
ppt18
ppt18ppt18
ppt18
 
Ruby for Perl Programmers
Ruby for Perl ProgrammersRuby for Perl Programmers
Ruby for Perl Programmers
 
ppt9
ppt9ppt9
ppt9
 

Plus de Shrinivasan T

Tamilinayavaani - integrating tva open-source spellchecker with python
Tamilinayavaani -  integrating tva open-source spellchecker with pythonTamilinayavaani -  integrating tva open-source spellchecker with python
Tamilinayavaani - integrating tva open-source spellchecker with python
Shrinivasan T
 
கட்டற்ற மென்பொருள் பற்றிய அறிமுகம் - தமிழில் - Introduction to Open source in...
கட்டற்ற மென்பொருள் பற்றிய அறிமுகம் - தமிழில் - Introduction to Open source in...கட்டற்ற மென்பொருள் பற்றிய அறிமுகம் - தமிழில் - Introduction to Open source in...
கட்டற்ற மென்பொருள் பற்றிய அறிமுகம் - தமிழில் - Introduction to Open source in...
Shrinivasan T
 
Sprit of Engineering
Sprit of EngineeringSprit of Engineering
Sprit of Engineering
Shrinivasan T
 

Plus de Shrinivasan T (20)

Giving New Life to Old Tamil Little Magazines Through Digitization
Giving New Life to Old Tamil Little Magazines Through DigitizationGiving New Life to Old Tamil Little Magazines Through Digitization
Giving New Life to Old Tamil Little Magazines Through Digitization
 
Digitization of Tamil Soviet Publications and Little Magazines.pdf
Digitization of Tamil Soviet Publications and Little Magazines.pdfDigitization of Tamil Soviet Publications and Little Magazines.pdf
Digitization of Tamil Soviet Publications and Little Magazines.pdf
 
python-an-introduction
python-an-introductionpython-an-introduction
python-an-introduction
 
Tamilinayavaani - integrating tva open-source spellchecker with python
Tamilinayavaani -  integrating tva open-source spellchecker with pythonTamilinayavaani -  integrating tva open-source spellchecker with python
Tamilinayavaani - integrating tva open-source spellchecker with python
 
Algorithms for certain classes of tamil spelling correction
Algorithms for certain classes of tamil spelling correctionAlgorithms for certain classes of tamil spelling correction
Algorithms for certain classes of tamil spelling correction
 
Tamil and-free-software - தமிழும் கட்டற்ற மென்பொருட்களும்
Tamil and-free-software - தமிழும் கட்டற்ற மென்பொருட்களும்Tamil and-free-software - தமிழும் கட்டற்ற மென்பொருட்களும்
Tamil and-free-software - தமிழும் கட்டற்ற மென்பொருட்களும்
 
Introducing FreeTamilEbooks
Introducing FreeTamilEbooks Introducing FreeTamilEbooks
Introducing FreeTamilEbooks
 
கணித்தமிழும் மென்பொருள்களும் - தேவைகளும் தீர்வுகளும்
கணித்தமிழும் மென்பொருள்களும் - தேவைகளும் தீர்வுகளும் கணித்தமிழும் மென்பொருள்களும் - தேவைகளும் தீர்வுகளும்
கணித்தமிழும் மென்பொருள்களும் - தேவைகளும் தீர்வுகளும்
 
Contribute to free open source software tamil - கட்டற்ற மென்பொருளுக்கு பங்களி...
Contribute to free open source software tamil - கட்டற்ற மென்பொருளுக்கு பங்களி...Contribute to free open source software tamil - கட்டற்ற மென்பொருளுக்கு பங்களி...
Contribute to free open source software tamil - கட்டற்ற மென்பொருளுக்கு பங்களி...
 
ஏன் லினக்ஸ் பயன்படுத்த வேண்டும்? - Why Linux? in Tamil
ஏன் லினக்ஸ் பயன்படுத்த வேண்டும்? - Why Linux? in Tamilஏன் லினக்ஸ் பயன்படுத்த வேண்டும்? - Why Linux? in Tamil
ஏன் லினக்ஸ் பயன்படுத்த வேண்டும்? - Why Linux? in Tamil
 
கட்டற்ற மென்பொருள் பற்றிய அறிமுகம் - தமிழில் - Introduction to Open source in...
கட்டற்ற மென்பொருள் பற்றிய அறிமுகம் - தமிழில் - Introduction to Open source in...கட்டற்ற மென்பொருள் பற்றிய அறிமுகம் - தமிழில் - Introduction to Open source in...
கட்டற்ற மென்பொருள் பற்றிய அறிமுகம் - தமிழில் - Introduction to Open source in...
 
Share your knowledge in wikipedia
Share your knowledge in wikipediaShare your knowledge in wikipedia
Share your knowledge in wikipedia
 
Open-Tamil Python Library for Tamil Text Processing
Open-Tamil Python Library for Tamil Text ProcessingOpen-Tamil Python Library for Tamil Text Processing
Open-Tamil Python Library for Tamil Text Processing
 
Version control-systems
Version control-systemsVersion control-systems
Version control-systems
 
Contribute to-ubuntu
Contribute to-ubuntuContribute to-ubuntu
Contribute to-ubuntu
 
Dhvani TTS
Dhvani TTSDhvani TTS
Dhvani TTS
 
Freedom toaster
Freedom toasterFreedom toaster
Freedom toaster
 
Sprit of Engineering
Sprit of EngineeringSprit of Engineering
Sprit of Engineering
 
Amace ion newsletter-01
Amace ion   newsletter-01Amace ion   newsletter-01
Amace ion newsletter-01
 
Rpm Introduction
Rpm IntroductionRpm Introduction
Rpm Introduction
 

Dernier

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Dernier (20)

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 

Ruby An Introduction