Ruby 1.9 Introduction

4,141 views
3,978 views

Published on

Slides from my very introductory talk on Ruby 1.9 given at SD Ruby in April 2009.

Published in: Technology, Education
1 Comment
17 Likes
Statistics
Notes
  • As a management instructor I appreciate viewing the work of others. This is one of the best demonstration on planning I've viewed.
    Sharika
    http://winkhealth.com http://financewink.com
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
No Downloads
Views
Total views
4,141
On SlideShare
0
From Embeds
0
Number of Embeds
63
Actions
Shares
0
Downloads
288
Comments
1
Likes
17
Embeds 0
No embeds

No notes for slide













































  • Ruby 1.9 Introduction

    1. 1. Ruby1.9.1
    2. 2. Ruby1.9.1 Brad Feeley
    3. 3. Ruby1.9.1 Brad Feeley I work at Digitaria
    4. 4. Ruby1.9.1 What is it?
    5. 5. Ruby1.9.1 What is it? “ Ruby 1.9 is a new series of Ruby. It is modern, faster, with clearer syntax, multilingualized, a much improved version of Ruby.
    6. 6. Ruby1.9.1 Faster JRuby
    7. 7. Ruby1.9.1 Faster New virtual machine YARV
    8. 8. Ruby1.9.1 Faster Maybe another presentation? New virtual machine YARV Kernal (native) threads
    9. 9. Ruby1.9.1 Multilingualized a.k.a. m17n
    10. 10. Ruby1.9.1 Multilingualized File Level Encoding
    11. 11. Ruby1.9.1 Multilingualized File Level Encoding # encodeing: utf-8 alias π = Math::PI
    12. 12. Ruby1.9.1 Multilingualized String Level Encoding
    13. 13. Ruby1.9.1 Multilingualized String Level Encoding my_string.encode(“iso-8859-1”)
    14. 14. Ruby1.9.1 Multilingualized IO Level Encoding
    15. 15. Ruby1.9.1 Multilingualized IO Level Encoding f.open(‘file.txt’, ‘r:ascii’) data = f.read data.encoding.name # => ‘US-ASCII’
    16. 16. Ruby1.9.1 Cleaner Syntax
    17. 17. Cleaner Syntax Ruby1.9.1 String No longer Enumerable
    18. 18. Cleaner Syntax Ruby1.9.1 String No longer Enumerable 1.8 String.ancestors => [String, Enumerable, Comparable, Object, Kernel] 1.9 String.ancestors => [String, Comparable, Object, Kernel]
    19. 19. Cleaner Syntax Ruby1.9.1 String No longer Enumerable 1.8 my_string_var.each { |line| puts line } 1.9 my_string_var.each_line { |line| puts line }
    20. 20. Cleaner Syntax Ruby1.9.1 String str = “test” str.clear # => “” “hellonworld”.lines # => [“hellon”, “world”] “hello”.encoding # => “UTF-8” “kitty”.start_with? “cat” # => false “kitty”.end_with? “tty” # => true
    21. 21. Cleaner Syntax Ruby1.9.1 Array
    22. 22. Cleaner Syntax Ruby1.9.1 Array vowels = ['a','e','i', ‘o’, ‘u’] vowels.index{|letter| letter == 'e'} # => 1 a = [1,2,3] a.permutation(2).to_a #=> [[1,2],[1,3],[2,1],[2,3],[3,1],[3,2]] a.combination(2).to_a #=> [[1, 2], [1, 3], [2, 3]] a.to_s # => “[1, 2, 3]” a.pop(2) #=> [2, 3]
    23. 23. Cleaner Syntax Ruby1.9.1 Hash
    24. 24. Cleaner Syntax Ruby1.9.1 Hash New Key Value Syntax
    25. 25. Cleaner Syntax Ruby1.9.1 Hash New Key Value Syntax 1.8 render :action => ‘new’
    26. 26. Cleaner Syntax Ruby1.9.1 Hash New Key Value Syntax 1.8 render :action => ‘new’ 1.9 render action: ‘new’
    27. 27. Cleaner Syntax Ruby1.9.1 Hash Order Preservation h = {:a => 1, :b => 2, :c => 3 } h[:d] = 4 1.8 puts h.inspect => {:4 => d, :a => 1, :b => 2, :c => 3 }
    28. 28. Cleaner Syntax Ruby1.9.1 Hash Order Preservation h = {:a => 1, :b => 2, :c => 3 } h[:d] = 4 1.8 puts h.inspect => {:4 => d, :a => 1, :b => 2, :c => 3 } 1.9 puts h.inspect => {:a => 1, :b => 2, :c => 3, :4 => d }
    29. 29. Cleaner Syntax Ruby1.9.1 Proc
    30. 30. Cleaner Syntax Ruby1.9.1 Proc New Declaration Syntax 1.8 say_hi = lambda { |a| “Hello, #{a}” }
    31. 31. Cleaner Syntax Ruby1.9.1 Proc New Declaration Syntax 1.8 say_hi = lambda { |a| “Hello, #{a}” } 1.9 say_hi = ->(a){ “Hello, #{a}” }
    32. 32. Cleaner Syntax Ruby1.9.1 Proc New Declaration Syntax 1.8 a = lambda { |x, y=1| x * y } #=> ERROR
    33. 33. Cleaner Syntax Ruby1.9.1 Proc New Declaration Syntax 1.8 a = lambda { |x, y=1| x * y } #=> ERROR 1.9 a = ->(x, y=1){ x * y } a = ->(&x){ x.call }
    34. 34. Cleaner Syntax Ruby1.9.1 Proc New Calling Syntax say_hi = lambda { |a| “Hello, #{a}” } 1.8 say_hi.call(‘Quentin’) # => Hello, Quentin
    35. 35. Cleaner Syntax Ruby1.9.1 Proc New Calling Syntax say_hi = lambda { |a| “Hello, #{a}” } 1.8 say_hi.call(‘Quentin’) # => Hello, Quentin 1.9 say_hi.(‘Quentin’) # => Hello, Quentin
    36. 36. Cleaner Syntax Ruby1.9.1 Block Scope n = “Hello, World!” [1,2,3].each do |n| #do something end
    37. 37. Cleaner Syntax Ruby1.9.1 Block Scope n = “Hello, World!” [1,2,3].each do |n| #do something end 1.8 puts n # => 3
    38. 38. Cleaner Syntax Ruby1.9.1 Block Scope n = “Hello, World!” [1,2,3].each do |n| #do something end 1.8 puts n # => 3 1.9 puts n # => “Hello, World!”
    39. 39. Cleaner Syntax Ruby1.9.1 Debugging
    40. 40. Cleaner Syntax Ruby1.9.1 Debugging -w whitespace
    41. 41. Cleaner Syntax Ruby1.9.1 Debugging -w whitespace Method#owner #=> module the method belongs to Method#source_location #=> where the method is defined
    42. 42. Ruby1.9.1 Installation http://gist.github.com/59130 wget ftp://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.1-p0.tar.bz2 tar -xjvf ruby-1.9.1-p0.tar.bz2 cd ruby-1.9.1-p0 ./configure --prefix=/usr --program-suffix=19 --enable-shared make && make install
    43. 43. Ruby1.9.1 Ruby on Rails
    44. 44. Ruby1.9.1 Resources •http://www.google.com
    45. 45. Ruby1.9.1 Questions?

    ×