Introduction to Ruby Programming Language

Introduction to Ruby Programming Language

Created for For SARCCOM Indonesia meetup

C24ae68993d2245ac88e24ccc8457a8c?s=128

Didik Wicaksono

August 26, 2017
Tweet

Transcript

  1. Ruby Programming Language

  2. Didik Wicaksono CTO Cookpad Indonesia

  3. Github: firewalker06 Twitter: did1k

  4. I work in

  5. Its where I learn to program with Ruby

  6. The question is: Why Ruby?

  7. Meet Matz

  8. He invented Ruby in 1995

  9. He designed Ruby to be human-oriented

  10. Ruby syntax is designed to be elegant

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

  12. print "elephant" if "elephant".include? "ant" You can speak this in

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

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

    proper english: “Print elephant if elephant include ant”
  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"
  16. print "elephant" if "elephant".include? "ant" “if” can be used to

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

    modify expression Method name can have question mark
  18. Writing Ruby code is easy because it can be written

    in plain english
  19. Programmer can express themselves into their code

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

    code
  21. humans.obliterate!

  22. humans.obliterate! unless humans.nice?

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

    Ruby
  24. false 2.negative? 2 < 0

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

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

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

    two, three = [1, 2, 3] one, two, three = 1, 2, 3 You don’t even need
  28. [1, 2, 3, 4, 5].map { |element| element if element.even?

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

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

  31. Block arguments also makes Ruby popular

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

  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"]

  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
  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
  36. Almost forgot! %w(Google Yahoo MSN).map do |engine| "https://www.#{engine.downcase}.com" end Is

    equal: ["Google", "Yahoo", "MSN"]
  37. More Blocks

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

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

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

  41. [ ["jakarta", "province"], ["bandung", "city"] ].each do |name, type| puts

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

    type| puts "#{name}_#{type}" end
  43. This kind of flexibility improves the joy of programming

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

  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!
  46. [1, 2, 3, 4, 5].select(&:even?) [2,4] FLASHBACK!

  47. Who doesn’t want to write less?

  48. Have you tried programming with Ruby?

  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/
  50. It only takes 20 minutes to learn Ruby from this

    page: https://www.ruby-lang.org/en/docu mentation/quickstart/
  51. There is also tutorials in Bahasa Indonesia: https://www.idrails.com/

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

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

  54. MINASWAN (Matz is nice and so we are nice) みなさん

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

    (read: mina-san) translation: everyone (polite)
  56. Friday Hug

  57. None
  58. None
  59. In Indonesia, we are known as ID-Ruby We are active

    on Slack and Telegram
  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
  61. We held meetups regularly

  62. We held meetups regularly

  63. Ruby ecosystem is huge

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

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

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

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

    2006
  68. Its over 10 years, but Rails is still on demand!

    https://infinum.co/the-capsized-eight/analyzing-rubygems-stats-v2016
  69. Big companies that uses Ruby

  70. • Github • Heroku • Airbnb • Shopify

  71. How about in Indonesia?

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

  73. Now you know!

  74. List of Ruby companies in Indonesia can be seen in

    ID-Ruby homepage!
  75. None
  76. Feel free to browse http://ruby.id !

  77. How about?

  78. Started using Rails on ver 1.2.3 with Ruby 1.8.7

  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!)
  80. Previously we used ColdFusion

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

  82. Our app servers run less than 100ms

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

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

  85. You can still be productive and run fast web application

    with Ruby on Rails