0
Ruby – An Introduction
          T.Arulalan
          tarulalan@gmail.com

          II Year, M.C.A,
          Saveetha En...
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     ●
       ...
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
el...
Quick and Easy
●
         Intrepreted Scripting Language
●
         Variable declarations are unnecessary
●
         Varia...
Object Oriented Programming
●
         Everything is an object
●
         classes, methods, inheritance, etc.
●
         s...
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]
=> qu...
Array
numbers = [ quot;zeroquot;, quot;onequot;, quot;twoquot;,
 quot;threequot;, quot;fourquot; ]


>> numbers[3].upcase
...
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;...
Multi Type Array
names = [ quot;Shriniquot;, quot;Balaquot;,
 quot;Sureshquot;, quot;Arulquot;, 1, 14, 45,
 77, 98.3, 3.14...
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[:...
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...
THE END
   of code :-)
How to Learn?
irb
●   interactive ruby
●   A ruby Shellnce 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/
Arulalan  Ruby An Intro
Arulalan  Ruby An Intro
Arulalan  Ruby An Intro
Arulalan  Ruby An Intro
Arulalan  Ruby An Intro
Upcoming SlideShare
Loading in...5
×

Arulalan Ruby An Intro

995

Published on

Ruby an introduction. It is 100% OOP Language. And it is very beautiful language.
I Love Ruby Very Much. I hope "YOU" too

Published in: Education, Technology
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
995
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
42
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

Transcript of "Arulalan Ruby An Intro"

  1. 1. Ruby – An Introduction T.Arulalan tarulalan@gmail.com II Year, M.C.A, Saveetha Enginnering College, Chennai – 602 105
  2. 2. Ruby is a Programming Language
  3. 3. There are so many  Programming Languages. Why  Ruby?
  4. 4. Ruby is simple and beautiful
  5. 5. Ruby is Easy to Learn
  6. 6. Ruby is Free Open Source Software
  7. 7. Ruby on Rails – Web Framework
  8. 8. RAA ● Ruby Application Archive ● 1648 projects ● http://raa.ruby-lang.org
  9. 9. Rubyforge ● 5070 projects and libraries ● http://rubyforge.org/
  10. 10. Can do ● Text Handling ● Games ● System Administration ● NLP ● GUI programming ● Web Applications ● ... ● Database Apps ● Scientific Applications
  11. 11. History
  12. 12. Ruby Yukihiro “Matz” Matsumoto Japan February 24, 1993
  13. 13.  Perl  Java  Python  Ruby  PHP 1987       1991         1993  1995
  14. 14.         What is Ruby?
  15. 15. 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.
  16. 16. Quick and Easy ●      Intrepreted Scripting Language ●      Variable declarations are unnecessary ●      Variables are not typed ●      syntax is simple and consistent ●      memory management is automatic
  17. 17. Object Oriented Programming ●      Everything is an object ●      classes, methods, inheritance, etc. ●      singleton methods ●      quot;mixinquot; functionality by module ●      iterators and closures
  18. 18. Examples!
  19. 19. 5.times { print “Ruby! quot; }
  20. 20. 5.times { print “Ruby! quot; } Ruby! Ruby! Ruby! Ruby! Ruby!
  21. 21. Everything is an object
  22. 22. 100.next
  23. 23. 100.next 101
  24. 24. “I love Ruby”  .reverse.capitalize
  25. 25. “I love Ruby”  .reverse.capitalize “Ybur evol i”
  26. 26. 3.hours.from_now
  27. 27. 3.hours.from_now Thu Jan 19 22:05:00 Eastern  Standard Time 2006
  28. 28. Conventions
  29. 29. Variables colored_index_cards
  30. 30. Class Names Person
  31. 31. Symbols :street_name
  32. 32. Instance Variables @school_name
  33. 33. Constants Kilograms_Per_Pound
  34. 34. Input
  35. 35. puts “What is Your name?” name = gets name = name.chomp puts quot;Helloquot; + name + quot; .Welcomequot;
  36. 36.             Flow
  37. 37. if ( score >= 5000 ) puts “You win!” elsif ( score <= 0 ) puts “Game over.” else puts “Current score: #{score}” end
  38. 38. puts “PASS” if mark > 35
  39. 39.                     Loop
  40. 40. count = 0 5.times do count += 1 puts quot;Count =quot; + count.to_s end
  41. 41. Count = 1 Count = 2 Count = 3 Count = 4 Count = 5
  42. 42. count = 0 while count < 10 puts quot;Count = quot; +count.to_s count += 1 end
  43. 43. Blocks
  44. 44. 1.upto(5) { |x| puts x } 1 2 3 4 5
  45. 45. 5.downto(1) do |time| print “#{time}... ” puts “!” if time <= 3 end 5... 4... 3... ! 2... ! 1... !
  46. 46. Array
  47. 47. Array numbers = [ quot;zeroquot;, quot;onequot;, quot;twoquot;, quot;threequot;, quot;fourquot; ]  
  48. 48. Array numbers = [ quot;zeroquot;, quot;onequot;, quot;twoquot;, quot;threequot;, quot;fourquot; ]   >> numbers[0] => quot;zeroquot; >> numbers[4] => quot;fourquot;
  49. 49. Array numbers = [ quot;zeroquot;, quot;onequot;, quot;twoquot;, quot;threequot;, quot;fourquot; ] >> numbers[3].upcase => quot;THREEquot; >> numbers[3].reverse => quot;eerhtquot;
  50. 50. Sort Array primes = [ 11, 5, 7, 2, 13, 3 ]
  51. 51. Sort Array primes = [ 11, 5, 7, 2, 13, 3 ] primes.sort
  52. 52. Sort Array primes = [ 11, 5, 7, 2, 13, 3 ] primes.sort => [2, 3, 5, 7, 11, 13]
  53. 53. Sort Array names = [ quot;Shriniquot;, quot;Balaquot;, quot;Sureshquot;, quot;Arulquot;]
  54. 54. Sort Array names = [ quot;Shriniquot;, quot;Balaquot;, quot;Sureshquot;, quot;Arulquot;] names.sort
  55. 55. Sort Array names = [ quot;Shriniquot;, quot;Balaquot;, quot;Sureshquot;, quot;Arulquot;] names.sort =>[quot;Arulquot;, quot;Balaquot;, quot;Shriniquot;, quot;Sureshquot;]
  56. 56. Multi Type Array names = [ quot;Shriniquot;, quot;Balaquot;, quot;Sureshquot;, quot;Arulquot;, 1, 14, 45, 77, 98.3, 3.14 ]
  57. 57. More on Arrays ● Reverse ● Length ● Delete ● Join ● Find ● More than 100 methods
  58. 58. Hashes
  59. 59. menu = { :idly => 2.50, :dosai => 10.00, :coffee => 5.00, :ice_cream => 5.00 } menu[:idly] 2.50
  60. 60. Methods
  61. 61. Methods def say_hello(name) result = “Hello, #{name}!” return result end puts say_hello(“world”)
  62. 62. Methods def say_hello(name) “Hello, #{name}!” end puts say_hello(“world”)
  63. 63. Class
  64. 64. Classes class MathWhiz def say_square(value) puts value * value end end sam = MathWhiz.new sam.say_square(5)
  65. 65. Inheritance class Dog < Animal @catagory = “mammal” @legs = 4 end
  66. 66. Module
  67. 67. Modules module Trig PI = 3.141592654 def Trig.sin(x) # .. end def Trig.cos(x) # .. end end
  68. 68. Modules require quot;trigquot; y = Trig.sin(Trig::PI/4) 0.707106780551956
  69. 69. Attributes class PlainOldRubyObject attr_accessor :food, :drinks attr_reader :advice attr_writer :write_only end
  70. 70. Scope class Poet #public by default def poetry end protected def family_legacy end private def hopes_and_dreams end end
  71. 71. THE END of code :-)
  72. 72. How to Learn?
  73. 73. irb ● interactive ruby ● A ruby Shellnce response ● learn as you type
  74. 74. Web sites Web Sites
  75. 75. http://ruby­lang.org www.ruby­lang.org
  76. 76. www.rubyforge.net
  77. 77. http://www.ruby­forum.com/
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×