Let's Learn Ruby - Basic

2,406 views
2,281 views

Published on

Published in: Technology
0 Comments
3 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
2,406
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
106
Comments
0
Likes
3
Embeds 0
No embeds

No notes for slide

Let's Learn Ruby - Basic

  1. 1. Let’s Learn Ruby - Basic
  2. 2. Ruby Tuesday photo by othree https://www.facebook.com/groups/142197385837507/
  3. 3. RubyConf Taiwan http://rubyconf.tw/
  4. 4. Rails Girls Taipei https://www.facebook.com/railsgirlstw
  5. 5. WebConf Taiwan 2014
  6. 6. 750+ attendees
  7. 7. all tickets sold out in 4 mins
  8. 8. Let’s Learn Ruby What I want?
  9. 9. Let’s Learn Ruby Problem Solving
  10. 10. Let’s Learn Ruby Active Ecosystem
  11. 11. Let’s Learn Ruby Scenario
  12. 12. Let’s Learn Ruby open source projects on Github
  13. 13. Let’s Learn Ruby History
  14. 14. Let’s Learn Ruby まつもと ゆきひろ (Matz)
  15. 15. Let’s Learn Ruby
  16. 16. Let’s Learn Ruby first released at 1995
  17. 17. Let’s Learn Ruby 2.0 released at 2013
  18. 18. Let’s Learn Ruby 2.1 released at 2013.12
  19. 19. Let’s Learn Ruby Why Ruby? free, open source, easy to learn
  20. 20. Let’s Learn Ruby Ruby != Rails
  21. 21. Let’s Learn Ruby Happy, and Fun
  22. 22. Let’s Learn Ruby Rubies CRuby(MRI), REE, mRuby, MacRuby, JRuby, IronRuby, Rubinius..etc
  23. 23. Let’s Learn Ruby Version 1.8, 1.9, 2.0, 2.1
  24. 24. Let’s Learn Ruby Ruby 1.8 has no future
  25. 25. Let’s Learn Ruby RVM Ruby Version Manager https://rvm.io/
  26. 26. Let’s Learn Ruby Editors Vim, Emacs, Sublime Text... etc
  27. 27. Let’s Learn Ruby coding style https://github.com/styleguide/ruby
  28. 28. Let’s Learn Ruby But Ruby is Slow..?
  29. 29. Let’s Learn Ruby What can Ruby do?
  30. 30. Let’s Learn Ruby Rake Make, but Ruby version. Rack http://rake.rubyforge.org/
  31. 31. Let’s Learn Ruby Rack it’s a specification (and implementation) of a minimal abstract Ruby API that models HTTP. such as Sinatra, Ruby on Rails Rack http://rack.rubyforge.org/ Sinatra http://www.sinatrarb.com Ruby on Rails http://rubyonrails.org/
  32. 32. Let’s Learn Ruby developing MacOS and iOS app
  33. 33. Let’s Learn Ruby drawing, image processing, music..
  34. 34. Let’s Learn Ruby Install Ruby now!
  35. 35. Let’s Learn Ruby http://tryruby.org
  36. 36. Let’s Learn Ruby Interactive Ruby, irb
  37. 37. Let’s Learn Ruby Gem
  38. 38. Let’s Learn Ruby gem install PACKAGE_NAME
  39. 39. Let’s Learn Ruby gem env
  40. 40. Let’s Learn Ruby gem list
  41. 41. Let’s Learn Ruby Variables and Constants
  42. 42. Let’s Learn Ruby local variable variable
  43. 43. Let’s Learn Ruby global variable $variable
  44. 44. Let’s Learn Ruby instance variable @variable
  45. 45. Let’s Learn Ruby class variable @@variable
  46. 46. Let’s Learn Ruby virtual variable true, false, self, nil
  47. 47. Let’s Learn Ruby variable assignment a=1 x, y, z = 1, 2, 3
  48. 48. Let’s Learn Ruby Constant begins with a capital letter, and it can be changed
  49. 49. Let’s Learn Ruby Reserved word and Keyword
  50. 50. Let’s Learn Ruby Reserved word and Keyword
  51. 51. Let’s Learn Ruby Logic and Flow Control
  52. 52. Let’s Learn Ruby only false and nil are false
  53. 53. Let’s Learn Ruby true v.s TrueClass false v.s FalseClass nil v.s NilClass
  54. 54. Let’s Learn Ruby if..elsif..end
  55. 55. Let’s Learn Ruby unless = not if
  56. 56. Let’s Learn Ruby if modifier
  57. 57. Let’s Learn Ruby case .. when..
  58. 58. Let’s Learn Ruby BEGIN{} and END{}
  59. 59. Let’s Learn Ruby a = true ? 'a' : 'b'
  60. 60. Let’s Learn Ruby a ||= 'a'
  61. 61. Let’s Learn Ruby Comment # single line
  62. 62. Let’s Learn Ruby Comment =begin .. =end
  63. 63. Let’s Learn Ruby Loop and Iteration
  64. 64. Let’s Learn Ruby for.. in..
  65. 65. Let’s Learn Ruby while .. end
  66. 66. Let’s Learn Ruby until .. end
  67. 67. Let’s Learn Ruby until = not while
  68. 68. Let’s Learn Ruby times
  69. 69. Let’s Learn Ruby upto, downto
  70. 70. Let’s Learn Ruby each, each_with_index
  71. 71. Let’s Learn Ruby Integer http://www.ruby-doc.org/core-2.1.0/Integer.html
  72. 72. Let’s Learn Ruby Fixnum and Bignum
  73. 73. Let’s Learn Ruby 10 / 3
  74. 74. Let’s Learn Ruby String http://ruby-doc.org/core-2.1.0/String.html
  75. 75. Let’s Learn Ruby single and double quotes
  76. 76. Let’s Learn Ruby %q v.s %Q
  77. 77. Let’s Learn Ruby "%s" % "eddie"
  78. 78. Let’s Learn Ruby string interpolation
  79. 79. Let’s Learn Ruby Exercise please calculate how many “characters” and “words” of a section of a random article with Ruby.
  80. 80. Let’s Learn Ruby Exercise please convert string “abcdefg” to “gfedcba” without using String#reverse method.
  81. 81. Let’s Learn Ruby Array http://ruby-doc.org/core-2.1.0/Array.html
  82. 82. Let’s Learn Ruby Array.new v.s []
  83. 83. Let’s Learn Ruby %w
  84. 84. Let’s Learn Ruby Exercise please sort a given array [1, 3, 4, 1, 7, nil, 7], and remove nil and duplicate number.
  85. 85. Let’s Learn Ruby Exercise please covert a given array [1, 2, 3, 4, 5] to [1, 3, 5, 7, 9] with Array#map method.
  86. 86. Let’s Learn Ruby Exercise please draw 5 unique random number between 1 to 52.
  87. 87. Let’s Learn Ruby Hash http://ruby-doc.org/core-2.1.0/Hash.html
  88. 88. Let’s Learn Ruby Hash.new v.s {}
  89. 89. Let’s Learn Ruby a = { :name => 'eddie' } a = { name: 'eddie' }
  90. 90. Let’s Learn Ruby Range http://ruby-doc.org/core-2.1.0/Range.html
  91. 91. Let’s Learn Ruby (1..10) v.s (1...10)
  92. 92. Let’s Learn Ruby Exercise please calculate the sum from 1 to 100 with Range.
  93. 93. Let’s Learn Ruby Methods
  94. 94. Let’s Learn Ruby def method_name(param) ... end
  95. 95. Let’s Learn Ruby parentheses can be omitted
  96. 96. Let’s Learn Ruby ? and !
  97. 97. Let’s Learn Ruby return value
  98. 98. Let’s Learn Ruby Singleton Method
  99. 99. Let’s Learn Ruby class Cat def walk puts "I'm walking" end end ! cat = Cat.new def cat.fly puts "I can fly" end cat.fly
  100. 100. Let’s Learn Ruby Method Missing
  101. 101. Let’s Learn Ruby def method_missing(method_name) puts "method: #{method_name} is called!" end ! something_not_exists()
  102. 102. Let’s Learn Ruby Exception Handling begin .. rescue.. else.. ensure.. end
  103. 103. Let’s Learn Ruby def open_my_file(file_name) File.open file_name do |f| puts f.read end end begin open_my_file("block_demo.r") rescue => e puts e else puts "it's working good!" ensure puts "this must be executed, no matter what" end
  104. 104. Let’s Learn Ruby Block
  105. 105. Let’s Learn Ruby Proc
  106. 106. Let’s Learn Ruby my_square = Proc.new { | x | x ** 2 } ! # how to call a proc puts my_square.call(10) puts my_square[10] puts my_square.(10) puts my_square === 10 # # # # 100 100 100 100
  107. 107. Let’s Learn Ruby lambda, ->
  108. 108. Let’s Learn Ruby my_lambda = lambda { | x | x ** 2 } ! # new style in 1.9 my_lambda = -> x { x ** 2 } ! # how to call a lambda? puts my_lambda.call(10) puts my_lambda[10] puts my_lambda.(10) puts my_lambda === 10 # # # # 100 100 100 100
  109. 109. Let’s Learn Ruby Proc v.s lambda
  110. 110. Let’s Learn Ruby def proc_test puts "hello" my_proc = Proc.new { return 1 } my_proc.call puts "ruby" end def lambda_test puts "hello" my_lambda = lambda { return 1 } my_lambda.call puts "ruby" end
  111. 111. Let’s Learn Ruby {} v.s do..end http://blog.eddie.com.tw/2011/06/03/do-end-vs-braces/
  112. 112. Let’s Learn Ruby Yield
  113. 113. Let’s Learn Ruby Object-Oriented Programming
  114. 114. Let’s Learn Ruby everything in Ruby is an Object
  115. 115. Let’s Learn Ruby object = state+ behavior
  116. 116. Let’s Learn Ruby root class = Object root class would be BasicObject in Ruby 1.9
  117. 117. Let’s Learn Ruby class ClassName < ParentClass ... end
  118. 118. Let’s Learn Ruby Naming Convention
  119. 119. Let’s Learn Ruby initialize
  120. 120. Let’s Learn Ruby ClassName.new
  121. 121. Let’s Learn Ruby self = current object
  122. 122. Let’s Learn Ruby instance and class variable
  123. 123. Let’s Learn Ruby instance and class method
  124. 124. Let’s Learn Ruby Exercise please create a Dog class and Cat class, which are both inherited from Animal class, and implement “walk” and “eat” methods.
  125. 125. Let’s Learn Ruby public, protected and private method
  126. 126. Let’s Learn Ruby getter and setter
  127. 127. Let’s Learn Ruby attr_reader, attr_writer and attr_accessor
  128. 128. Let’s Learn Ruby Open Class
  129. 129. Let’s Learn Ruby Module
  130. 130. Let’s Learn Ruby module ModuleName ... end
  131. 131. Let’s Learn Ruby module has no inheritance
  132. 132. Let’s Learn Ruby module has no instance
  133. 133. Let’s Learn Ruby Naming Convention
  134. 134. Let’s Learn Ruby require v.s load
  135. 135. Let’s Learn Ruby Priority?
  136. 136. Let’s Learn Ruby Exercise please create a Bird class, which is also inherited from Animal class, but include a Fly module.
  137. 137. Let’s Learn Ruby Mixin
  138. 138. Let’s Learn Ruby Ruby is single inheritance
  139. 139. Let’s Learn Ruby Duck Typing
  140. 140. Let’s Learn Ruby include v.s extend
  141. 141. Let’s Learn Ruby Bundle
  142. 142. Let’s Learn Ruby Gemfile
  143. 143. Let’s Learn Ruby http://rubygems.org/
  144. 144. Let’s Learn Ruby gem "nokogiri", :git => "git://github.com/ tenderlove/nokogiri.git" gem "secret_gem", :path => "~/my_secret_path"
  145. 145. Let’s Learn Ruby bundle install
  146. 146. Let’s Learn Ruby pack your own gem!
  147. 147. Let’s Learn Ruby 1. bundle gem NEW_NAME 2. gem build NEW_NAME.gemspec 3. gem push NEW_NAME.gem http://guides.rubygems.org/make-your-own-gem/
  148. 148. Let’s Learn Ruby Exercise please try to create a Gem spec with bundle command, modify, build and push to rubygems.org.
  149. 149. Let’s Learn Ruby Rake
  150. 150. Let’s Learn Ruby desc "mail sender" task :sendmail do puts "grap mailing list from database..." sleep 3 puts "mail sending..." sleep 3 puts "done!" end
  151. 151. Let’s Learn Ruby task :goto_toliet do puts "goto toliet" end ! task :open_the_door => :goto_toliet do puts "open door" end
  152. 152. Let’s Learn Ruby TDD
  153. 153. Let’s Learn Ruby require “minitest/autorun" ! class TestMyBMI < MiniTest::Unit::TestCase def test_my_calc_bmi_is_ok assert_equal calc_bmi(175, 80), 26.12 end end ! def calc_bmi(height, weight) bmi = ( weight / (height/100.0) ** 2 ).round(2) end
  154. 154. Let’s Learn Ruby require "minitest/autorun" describe "test my bmi calculator" do it "should calc the correct bmi" do calc_bmi(175, 80).must_equal 26.12 end end def calc_bmi(height, weight) bmi = ( weight / (height/100.0) ** 2 ).round(2) end
  155. 155. Let’s Learn Ruby Ruby Koans http://rubykoans.com/
  156. 156. Let’s Learn Ruby Ruby Object Model
  157. 157. Let’s Learn Ruby At last..
  158. 158. photo by redjar
  159. 159. Let’s Learn Ruby pick up one scripting language
  160. 160. photo by Quality & Style
  161. 161. Let’s Learn Ruby @eddiekao https://www.ruby-lang.org/zh_tw/
  162. 162. Let’s Learn Ruby Ruby is fun!
  163. 163. Let’s Learn Ruby The only limitation is your imagination.
  164. 164. Contacts ⾼高⾒見⻯⿓龍 Website http://www.eddie.com.tw Blog http://blog.eddie.com.tw Plurk http://www.plurk.com/aquarianboy Facebook http://www.facebook.com/eddiekao Google Plus http://www.eddie.com.tw/+ Twitter https://twitter.com/eddiekao Email eddie@digik.com.tw Mobile +886-928-617-687 photo by Eddie

×