Rochester on Rails: Introduction to Ruby

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    Favorites, Groups & Events

    Rochester on Rails: Introduction to Ruby - Presentation Transcript

    1. Ruby Programmers’ Best Friend Jason Morrison January 19, 2006 Rochester on Rails
    2. History
    3. Ruby Yukihiro “Matz” Matsumoto February 24, 1993
    4. Perl Java Python Ruby PHP 1987 1991 1993 1995
    5. Examples!
    6. 5.times { print “Ruby! " }
    7. Ruby! Ruby! Ruby! Ruby! Ruby! 5.times { print “Ruby! " }
    8. [‘one’,‘two’,‘three’].each {|num| puts num.capitalize }
    9. [‘one’,‘two’,‘three’].each {|num| puts num.capitalize } One Two Three
    10. Everything is an object
    11. -21474836480.abs
    12. -21474836480.abs 21474836480
    13. “ Rats live on no evil star”  .reverse.capitalize
    14. “ Rats live on no evil star”  .reverse.capitalize “ Rats live on no evil star”
    15. 3.hours.from_now
    16. 3.hours.from_now Thu Jan 19 22:05:00 Eastern  Standard Time 2006
    17. Conventions
    18. Variables colored_index_cards
    19. Class Names DromedaryDiner
    20. Symbols :creme_de_menthe
    21. Instance Variables @euros_per_liter
    22. Constants Kilograms_Per_Pound
    23. Syntax
    24. Methods def say_hello(name) result = “Hello, #{name}!” return result end puts say_hello(“world”)
    25. Methods def say_hello(name) “Hello, #{name}!” end puts say_hello(“world”)
    26. Classes class MathWhiz def say_square(value) puts value * value end end sam = MathWhiz.new sam.say_square(5)
    27. Open Classes class Integer def squared self * self end end 5.squared #=> 25
    28. Inheritance class Whopper < Burger @maker = “Burger King” @calories = 0.67 * 10**3 end
    29. Class Methods class FileUtil def self.mkdir(dir) # do it! end end FileUtil.mkdir(“oranges”)
    30. Modules module Trig PI = 3.141592654 def Trig.sin(x) # .. end def Trig.cos(x) # .. end end
    31. Modules require &quot;trig&quot; y = Trig.sin(Trig::PI/4) 0.707106780551956
    32. Mixins module Debug def whoAmI? “ #{self.type.name} ” + “ (##{self.id}): ” + “ #{self.to_s}&quot; end end
    33. Mixins class Phonograph include Debug # ... end ph = Phonograph.new(&quot;West End Blues&quot;) ph.whoAmI? &quot;Phonograph (#537766170): West End Blues&quot;
    34. Attributes class PlainOldRubyObject attr_accessor :food, :drinks attr_reader :advice attr_writer :write_only end
    35. Scope class Poet #public by default def poetry end protected def family_legacy end private def hopes_and_dreams end end
    36. Arrays
    37. foo = [] foo << 1 #=> [1] foo << 2 #=> [1, 2] foo << 3 #=> [1, 2, 3]
    38. bar = [1, 2, 3] bar << 4 #=> [1, 2, 3, 4] bar << 5 #=> [1, 2, 3, 4, 5] bar << 6 #=> [1, 2, 3, 4, 5, 6]
    39. folks = %w( Charles Ed Amanda ) #=> [“Charles”, “Ed”, “Amanda”] folks[1] Ed
    40. Hashes
    41. menu = { :douglas_sirk_steak => 17.50, :vanilla_coke => 2.75, :durwood_kirby_burger => 9.75, :five_dollar_shake => 5.00 } menu[:vanilla_coke] 2.75
    42. Flow
    43. if ( score >= 5000 ) puts “You win!” elsif ( score <= 0 ) puts “Game over.” else puts “Current score: #{score}” end
    44. puts “Watch out!” if lion_distance < 5
    45. Blocks
    46. 1.upto(5) { |x| puts x } 1 2 3 4 5
    47. 5.downto(1) do |time| print “#{time}... ” puts “!” if time <= 3 end 5... 4... 3... ! 2... ! 1... !
    48. Fín!
    49. Homepage www.ruby-lang.org Try Ruby in your browser tryruby.hobix.com Ruby with humor  www.poignantguide.net

    + Jason MorrisonJason Morrison, 2 years ago

    custom

    1645 views, 0 favs, 1 embeds more stats

    A brief and basic introduction to the syntax of Rub more

    More info about this document

    © All Rights Reserved

    Go to text version

    • Total Views 1645
      • 1639 on SlideShare
      • 6 from embeds
    • Comments 0
    • Favorites 0
    • Downloads 36
    Most viewed embeds
    • 6 views on http://jayunit.net

    more

    All embeds
    • 6 views on http://jayunit.net

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as inappropriate

    Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

    Cancel
    File a copyright complaint
    Having problems? Go to our helpdesk?

    Categories