Let's Learn Ruby - Basic

F2dcf6633971844e19ca96ea294ba976?s=47 高見龍
December 30, 2013

Let's Learn Ruby - Basic

F2dcf6633971844e19ca96ea294ba976?s=128

高見龍

December 30, 2013
Tweet

Transcript

  1. Let’s Learn Ruby - Basic

  2. None
  3. Ruby Tuesday https://www.facebook.com/groups/142197385837507/ photo by othree

  4. RubyConf Taiwan http://rubyconf.tw/ photo by othree

  5. Rails Girls Taipei https://www.facebook.com/railsgirlstw

  6. WebConf Taiwan 2014

  7. 750+ attendees

  8. all tickets sold out in 4 mins

  9. Let’s Learn Ruby What I want?

  10. Let’s Learn Ruby Problem Solving

  11. Let’s Learn Ruby Active Ecosystem

  12. Let’s Learn Ruby Scenario

  13. Let’s Learn Ruby open source projects on Github

  14. Let’s Learn Ruby History

  15. Let’s Learn Ruby まつもと ゆきひろ (Matz)

  16. Let’s Learn Ruby

  17. Let’s Learn Ruby first released at 1995

  18. Let’s Learn Ruby 2.0 released at 2013

  19. Let’s Learn Ruby 2.1 released at 2013.12

  20. Let’s Learn Ruby Why Ruby? free, open source, easy to

    learn
  21. Let’s Learn Ruby Ruby != Rails

  22. Let’s Learn Ruby Happy, and Fun

  23. Let’s Learn Ruby Rubies CRuby(MRI), REE, mRuby, MacRuby, JRuby, IronRuby,

    Rubinius..etc
  24. Let’s Learn Ruby Version 1.8, 1.9, 2.0, 2.1

  25. Let’s Learn Ruby Ruby 1.8 has no future

  26. Let’s Learn Ruby RVM Ruby Version Manager https://rvm.io/

  27. Let’s Learn Ruby Editors Vim, Emacs, Sublime Text... etc

  28. Let’s Learn Ruby coding style https://github.com/styleguide/ruby

  29. Let’s Learn Ruby But Ruby is Slow..?

  30. Let’s Learn Ruby What can Ruby do?

  31. Let’s Learn Ruby Rake Make, but Ruby version. Rack http://rake.rubyforge.org/

  32. 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/
  33. Let’s Learn Ruby developing MacOS and iOS app

  34. Let’s Learn Ruby drawing, image processing, music..

  35. Let’s Learn Ruby Install Ruby now!

  36. Let’s Learn Ruby http://tryruby.org

  37. Let’s Learn Ruby Interactive Ruby, irb

  38. Let’s Learn Ruby Gem

  39. Let’s Learn Ruby gem install PACKAGE_NAME

  40. Let’s Learn Ruby gem env

  41. Let’s Learn Ruby gem list

  42. Let’s Learn Ruby Variables and Constants

  43. Let’s Learn Ruby local variable variable

  44. Let’s Learn Ruby global variable $variable

  45. Let’s Learn Ruby instance variable @variable

  46. Let’s Learn Ruby class variable @@variable

  47. Let’s Learn Ruby virtual variable true, false, self, nil

  48. Let’s Learn Ruby variable assignment a = 1 x, y,

    z = 1, 2, 3
  49. Let’s Learn Ruby Constant begins with a capital letter, and

    it can be changed
  50. Let’s Learn Ruby Reserved word and Keyword

  51. Let’s Learn Ruby Reserved word and Keyword

  52. Let’s Learn Ruby Logic and Flow Control

  53. Let’s Learn Ruby only false and nil are false

  54. Let’s Learn Ruby true v.s TrueClass false v.s FalseClass nil

    v.s NilClass
  55. Let’s Learn Ruby if..elsif..end

  56. Let’s Learn Ruby unless = not if

  57. Let’s Learn Ruby if modifier

  58. Let’s Learn Ruby case .. when..

  59. Let’s Learn Ruby BEGIN{} and END{}

  60. Let’s Learn Ruby a = true ? 'a' : 'b'

  61. Let’s Learn Ruby a ||= 'a'

  62. Let’s Learn Ruby Comment # single line

  63. Let’s Learn Ruby Comment =begin .. =end

  64. Let’s Learn Ruby Loop and Iteration

  65. Let’s Learn Ruby for.. in..

  66. Let’s Learn Ruby while .. end

  67. Let’s Learn Ruby until .. end

  68. Let’s Learn Ruby until = not while

  69. Let’s Learn Ruby times

  70. Let’s Learn Ruby upto, downto

  71. Let’s Learn Ruby each, each_with_index

  72. Let’s Learn Ruby Integer http://www.ruby-doc.org/core-2.1.0/Integer.html

  73. Let’s Learn Ruby Fixnum and Bignum

  74. Let’s Learn Ruby 10 / 3

  75. Let’s Learn Ruby String http://ruby-doc.org/core-2.1.0/String.html

  76. Let’s Learn Ruby single and double quotes

  77. Let’s Learn Ruby %q v.s %Q

  78. Let’s Learn Ruby "%s" % "eddie"

  79. Let’s Learn Ruby string interpolation

  80. Let’s Learn Ruby Exercise please calculate how many “characters” and

    “words” of a section of a random article with Ruby.
  81. Let’s Learn Ruby Exercise please convert string “abcdefg” to “gfedcba”

    without using String#reverse method.
  82. Let’s Learn Ruby Array http://ruby-doc.org/core-2.1.0/Array.html

  83. Let’s Learn Ruby Array.new v.s []

  84. Let’s Learn Ruby %w

  85. Let’s Learn Ruby Exercise please sort a given array [1,

    3, 4, 1, 7, nil, 7], and remove nil and duplicate number.
  86. 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.
  87. Let’s Learn Ruby Exercise please draw 5 unique random number

    between 1 to 52.
  88. Let’s Learn Ruby Hash http://ruby-doc.org/core-2.1.0/Hash.html

  89. Let’s Learn Ruby Hash.new v.s {}

  90. Let’s Learn Ruby a = { :name => 'eddie' }

    a = { name: 'eddie' }
  91. Let’s Learn Ruby Range http://ruby-doc.org/core-2.1.0/Range.html

  92. Let’s Learn Ruby (1..10) v.s (1...10)

  93. Let’s Learn Ruby Exercise please calculate the sum from 1

    to 100 with Range.
  94. Let’s Learn Ruby Methods

  95. Let’s Learn Ruby def method_name(param) ... end

  96. Let’s Learn Ruby parentheses can be omitted

  97. Let’s Learn Ruby ? and !

  98. Let’s Learn Ruby return value

  99. Let’s Learn Ruby Singleton Method

  100. 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
  101. Let’s Learn Ruby Method Missing

  102. Let’s Learn Ruby def method_missing(method_name) puts "method: #{method_name} is called!"

    end ! something_not_exists()
  103. Let’s Learn Ruby Exception Handling begin .. rescue.. else.. ensure..

    end
  104. 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
  105. Let’s Learn Ruby Block

  106. Let’s Learn Ruby Proc

  107. Let’s Learn Ruby my_square = Proc.new { | x |

    x ** 2 } ! # how to call a proc puts my_square.call(10) # 100 puts my_square[10] # 100 puts my_square.(10) # 100 puts my_square === 10 # 100
  108. Let’s Learn Ruby lambda, ->

  109. 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) # 100 puts my_lambda[10] # 100 puts my_lambda.(10) # 100 puts my_lambda === 10 # 100
  110. Let’s Learn Ruby Proc v.s lambda

  111. 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
  112. Let’s Learn Ruby {} v.s do..end http://blog.eddie.com.tw/2011/06/03/do-end-vs-braces/

  113. Let’s Learn Ruby Yield

  114. Let’s Learn Ruby Object-Oriented Programming

  115. Let’s Learn Ruby everything in Ruby is an Object

  116. Let’s Learn Ruby object = state+ behavior

  117. Let’s Learn Ruby root class = Object root class would

    be BasicObject in Ruby 1.9
  118. Let’s Learn Ruby class ClassName < ParentClass ... end

  119. Let’s Learn Ruby Naming Convention

  120. Let’s Learn Ruby initialize

  121. Let’s Learn Ruby ClassName.new

  122. Let’s Learn Ruby self = current object

  123. Let’s Learn Ruby instance and class variable

  124. Let’s Learn Ruby instance and class method

  125. 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.
  126. Let’s Learn Ruby public, protected and private method

  127. Let’s Learn Ruby getter and setter

  128. Let’s Learn Ruby attr_reader, attr_writer and attr_accessor

  129. Let’s Learn Ruby Open Class

  130. Let’s Learn Ruby Module

  131. Let’s Learn Ruby module ModuleName ... end

  132. Let’s Learn Ruby module has no inheritance

  133. Let’s Learn Ruby module has no instance

  134. Let’s Learn Ruby Naming Convention

  135. Let’s Learn Ruby require v.s load

  136. Let’s Learn Ruby Priority?

  137. Let’s Learn Ruby Exercise please create a Bird class, which

    is also inherited from Animal class, but include a Fly module.
  138. Let’s Learn Ruby Mixin

  139. Let’s Learn Ruby Ruby is single inheritance

  140. Let’s Learn Ruby Duck Typing

  141. Let’s Learn Ruby include v.s extend

  142. Let’s Learn Ruby Bundle

  143. Let’s Learn Ruby Gemfile

  144. Let’s Learn Ruby http://rubygems.org/

  145. Let’s Learn Ruby gem "nokogiri", :git => "git://github.com/ tenderlove/nokogiri.git" gem

    "secret_gem", :path => "~/my_secret_path"
  146. Let’s Learn Ruby bundle install

  147. Let’s Learn Ruby pack your own gem!

  148. 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/
  149. Let’s Learn Ruby Exercise please try to create a Gem

    spec with bundle command, modify, build and push to rubygems.org.
  150. Let’s Learn Ruby Rake

  151. 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
  152. Let’s Learn Ruby task :goto_toliet do puts "goto toliet" end

    ! task :open_the_door => :goto_toliet do puts "open door" end
  153. Let’s Learn Ruby TDD

  154. 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
  155. 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
  156. Let’s Learn Ruby Ruby Koans http://rubykoans.com/

  157. Let’s Learn Ruby Ruby Object Model

  158. Let’s Learn Ruby At last..

  159. photo by redjar

  160. Let’s Learn Ruby pick up one scripting language

  161. photo by Quality & Style

  162. Let’s Learn Ruby @eddiekao https://www.ruby-lang.org/zh_tw/

  163. Let’s Learn Ruby Ruby is fun!

  164. Let’s Learn Ruby The only limitation is your imagination.

  165. ⾼高⾒見⻯⿓龍 Contacts photo by Eddie Website Blog Plurk Facebook Google

    Plus Twitter Email Mobile http://www.eddie.com.tw http://blog.eddie.com.tw http://www.plurk.com/aquarianboy http://www.facebook.com/eddiekao http://www.eddie.com.tw/+ https://twitter.com/eddiekao eddie@digik.com.tw +886-928-617-687