Ruby for Starter

Ruby for Starter

F2dcf6633971844e19ca96ea294ba976?s=128

高見龍

March 23, 2013
Tweet

Transcript

  1. 2.
  2. 7.
  3. 11.
  4. 20.

    git

  5. 40.
  6. 48.
  7. 51.
  8. 52.
  9. 53.

    my_square = Proc.new { | x | x ** 2

    } my_square.call(10) # 100 my_square[10] # 100
  10. 55.

    my_lambda = lambda { | x | x ** 2

    } # new style in 1.9 my_lambda = -> x { x ** 2 } # how to call a lambda? my_lambda.call(10) my_lambda[10]
  11. 57.

    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
  12. 59.
  13. 61.
  14. 69.

    %w

  15. 72.
  16. 75.
  17. 78.
  18. 81.

    class Cat def walk puts "I'm walking" end end cat

    = Cat.new def cat.fly puts "I can fly" end cat.fly
  19. 85.

    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
  20. 100.
  21. 101.
  22. 107.
  23. 111.

    Gem

  24. 113.
  25. 114.
  26. 115.
  27. 119.

    1. bundle gem NEW_NAME 2. gem build NEW_NAME.gemspec 3. gem

    push NEW_NAME.gem http://docs.rubygems.org/read/chapter/20
  28. 120.