Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Introduction to Ruby Programming Language

Introduction to Ruby Programming Language

Created for For SARCCOM Indonesia meetup

Didik Wicaksono

August 26, 2017
Tweet

More Decks by Didik Wicaksono

Other Decks in Technology

Transcript

  1. Ruby Programming Language

    View Slide

  2. Didik Wicaksono
    CTO Cookpad Indonesia

    View Slide

  3. Github: firewalker06
    Twitter: did1k

    View Slide

  4. I work in

    View Slide

  5. Its where I learn to program with
    Ruby

    View Slide

  6. The question is:
    Why Ruby?

    View Slide

  7. Meet Matz

    View Slide

  8. He invented Ruby in 1995

    View Slide

  9. He designed Ruby to be
    human-oriented

    View Slide

  10. Ruby syntax is designed to
    be elegant

    View Slide

  11. print "elephant" if "elephant".include? "ant"
    "elephant"

    View Slide

  12. print "elephant" if "elephant".include? "ant"
    You can speak this in proper english:
    “Print an elephant if elephant include ant”

    View Slide

  13. print "elephant" if "elephant".include? "ant"
    You can speak this in proper english:
    “Print elephant if elephant include ant”

    View Slide

  14. print "elephant" if "elephant".include? "ant"
    You can speak this in proper english:
    “Print elephant if elephant include ant”

    View Slide

  15. This sentence still doesn’t make any sense,
    but it is readable
    You can speak this in proper english:
    “Print elephant if elephant include ant”
    print "elephant" if "elephant".include? "ant"

    View Slide

  16. print "elephant" if "elephant".include? "ant"
    “if” can be used to modify expression

    View Slide

  17. print "elephant" if "elephant".include? "ant"
    “if” can be used to modify expression
    Method name can have question mark

    View Slide

  18. Writing Ruby code is easy
    because it can be written in
    plain english

    View Slide

  19. Programmer can express
    themselves into their code

    View Slide

  20. movie.awesome?
    bedroom.with_twin_beds?
    recipe.cooked_under 10.minutes
    Programmer can express
    themselves into their code

    View Slide

  21. humans.obliterate!

    View Slide

  22. humans.obliterate! unless humans.nice?

    View Slide

  23. There are more than one way
    to do anything in Ruby

    View Slide

  24. false
    2.negative?
    2 < 0

    View Slide

  25. "hello"
    puts "hello"
    $stdout.puts "hello"
    p "hello"

    View Slide

  26. one = 1
    two = 2
    three = 3
    one, two, three = [1, 2, 3]

    View Slide

  27. one = 1
    two = 2
    three = 3
    one, two, three = [1, 2, 3]
    one, two, three = 1, 2, 3
    You don’t even need

    View Slide

  28. [1, 2, 3, 4, 5].map { |element|
    element if element.even?
    }.compact
    [2,4]

    View Slide

  29. [1, 2, 3, 4, 5].
    select { |element| element.even? }
    [2,4]

    View Slide

  30. [1, 2, 3, 4, 5].select(&:even?)
    [2,4]

    View Slide

  31. Block arguments also
    makes Ruby popular

    View Slide

  32. method do
    ...
    end
    method do |argument|
    ...
    end

    View Slide

  33. %w(Google Yahoo MSN).map do |engine|
    "https://www.#{engine.downcase}.com"
    end
    ["https://www.google.com",
    "https://www.yahoo.com",
    "https://www.msn.com"]

    View Slide

  34. Blocks allows us to attach closure to
    any method
    %w(Google Yahoo MSN).map do |engine|
    "https://www.#{engine.downcase}.com"
    end
    this will be returned

    View Slide

  35. Blocks allows us to attach closure to
    any method
    %w(Google Yahoo MSN).map do |engine|
    "https://www.#{engine.downcase}.com"
    end
    this will be returned
    You don’t even need to write return

    View Slide

  36. Almost forgot!
    %w(Google Yahoo MSN).map do |engine|
    "https://www.#{engine.downcase}.com"
    end
    Is equal: ["Google", "Yahoo", "MSN"]

    View Slide

  37. More Blocks

    View Slide

  38. %w(jakarta bandung).map do |city|
    city.capitalize
    end

    View Slide

  39. %w(jakarta bandung).map do |city|
    city.capitalize
    end
    ["Jakarta", "Bandung"]

    View Slide

  40. %w(jakarta bandung).map(&:capitalize)
    ["Jakarta", "Bandung"]

    View Slide

  41. [
    ["jakarta", "province"],
    ["bandung", "city"]
    ].each do |name, type|
    puts "#{name}_#{type}"
    end

    View Slide

  42. "jakarta_province"
    "bandung_city"
    [
    ["jakarta", "province"],
    ["bandung", "city"]
    ].each do |name, type|
    puts "#{name}_#{type}"
    end

    View Slide

  43. This kind of flexibility
    improves the joy of
    programming

    View Slide

  44. You might notice that Ruby
    makes you write fewer
    codes

    View Slide

  45. one = 1
    two = 2
    three = 3
    one, two, three = [1, 2, 3]
    one, two, three = 1, 2, 3
    You don’t even need
    FLASHBACK!

    View Slide

  46. [1, 2, 3, 4, 5].select(&:even?)
    [2,4]
    FLASHBACK!

    View Slide

  47. Who doesn’t want to write
    less?

    View Slide

  48. Have you tried
    programming with Ruby?

    View Slide

  49. You might not noticed, but Mac users
    already have Ruby
    (even though its outdated)
    Installation is pretty easy:
    https://www.ruby-lang.org/en/docum
    entation/installation/

    View Slide

  50. It only takes 20 minutes to learn
    Ruby from this page:
    https://www.ruby-lang.org/en/docu
    mentation/quickstart/

    View Slide

  51. There is also tutorials in Bahasa
    Indonesia:
    https://www.idrails.com/

    View Slide

  52. How about you try to learn
    together with fellow
    Rubyists?

    View Slide

  53. Ruby community is
    known to be friendly
    (nice)

    View Slide

  54. MINASWAN
    (Matz is nice and so we are nice)
    みなさん (read: mina-san)
    translation: everyone (polite)

    View Slide

  55. MINASWAN
    (Matz is nice and so we are nice)
    みなさん (read: mina-san)
    translation: everyone (polite)

    View Slide

  56. Friday Hug

    View Slide

  57. View Slide

  58. View Slide

  59. In Indonesia, we are known as
    ID-Ruby
    We are active on Slack and Telegram

    View Slide

  60. In Indonesia, we are known as
    ID-Ruby
    We are active on Slack and Telegram
    Feel free to join: http://ruby.id/slack
    and https://t.me/ruby_id

    View Slide

  61. We held meetups regularly

    View Slide

  62. We held meetups regularly

    View Slide

  63. Ruby ecosystem is huge

    View Slide

  64. More than 135,000 gems in
    rubygems.org

    View Slide

  65. “Gems” are what we called
    as Ruby libraries

    View Slide

  66. One of the most popular gem is
    Ruby on Rails framework

    View Slide

  67. It is said that Rails made Ruby
    gaining popularity in 2006

    View Slide

  68. Its over 10 years, but Rails is still on
    demand!
    https://infinum.co/the-capsized-eight/analyzing-rubygems-stats-v2016

    View Slide

  69. Big companies that uses Ruby

    View Slide

  70. ● Github
    ● Heroku
    ● Airbnb
    ● Shopify

    View Slide

  71. How about in
    Indonesia?

    View Slide

  72. ● Bukalapak
    ● Go-Jek
    ● Midtrans
    ● Vidio

    View Slide

  73. Now you know!

    View Slide

  74. List of Ruby companies in
    Indonesia can be seen in
    ID-Ruby homepage!

    View Slide

  75. View Slide

  76. Feel free to browse http://ruby.id !

    View Slide

  77. How about?

    View Slide

  78. Started using Rails on ver
    1.2.3 with Ruby 1.8.7

    View Slide

  79. Current Rails version is 5.1 with
    Ruby 2.4
    Started using Rails on ver
    1.2.3 with Ruby 1.8.7 (2009!)

    View Slide

  80. Previously we used ColdFusion

    View Slide

  81. We have several large Rails
    applications running in Cookpad!

    View Slide

  82. Our app servers run less than
    100ms

    View Slide

  83. If you are interested
    https://speakerdeck.com/mirakui/high-performance-rails-long-edition

    View Slide

  84. If you are interested
    https://speakerdeck.com/a_matsuda/the-recip
    e-for-the-worlds-largest-rails-monolith

    View Slide

  85. You can still be productive and
    run fast web application with
    Ruby on Rails

    View Slide