Upgrade to Pro — share decks privately, control downloads, hide ads and more …

10 Things you should know about Ruby

10 Things you should know about Ruby

Interrest in Ruby? I think these are 10 things you should know about it.

This was presented in Barcamp Bangkok 4, Oct 23-24, 2010, at Sripathum University Bangkhen Campus.

Prem Sichanugrist

October 23, 2010
Tweet

More Decks by Prem Sichanugrist

Other Decks in Programming

Transcript

  1. 10 Things
    You Should Know About
    Ruby

    View Slide

  2. 1. Ruby != Rails

    View Slide

  3. • Programming Language
    • 1995 – First public release
    • Many Implementations
    • MRI 1.8 – Matz’s Ruby
    Intepreter
    • YARV 1.9
    • JRuby
    • IronRuby
    • Rubinius
    • MacRuby
    • MagLev

    View Slide

  4. “I wanted a scripting language that was more powerful
    than Perl, and more object-oriented than Python. That's
    why I decided to design my own language”

    View Slide

  5. Smalltalk
    Perl
    Lisp
    Scheme
    Python
    CLU
    Eiffel
    Ada
    Dylan
    {

    View Slide

  6. • Web application framework
    written in Ruby
    • “Ruby” on “Rails”
    • David Heinemeier Hansson
    (DHH)
    • Extracted from 37Signal’s
    Basecamp in 2004

    View Slide

  7. • Open Source
    • Currently maintained by
    Rails Core Team
    • git://github.com/rails/rails
    • Latest version: 3.0.1

    View Slide

  8. No more confusion!
    http://www.flickr.com/photos/ecstaticist/2589723846/

    View Slide

  9. 2. Simple syntax

    View Slide

  10. View Slide

  11. View Slide

  12. View Slide

  13. View Slide

  14. View Slide

  15. View Slide

  16. View Slide

  17. Too Easy!
    http://www.flickr.com/photos/clairity/143368932/

    View Slide

  18. 3. Pure Object-Oriented

    View Slide

  19. Everything in Ruby
    is Object

    View Slide

  20. No Primitive

    View Slide

  21. View Slide

  22. Even nil ...

    View Slide

  23. View Slide

  24. ... and class!

    View Slide

  25. View Slide

  26. http://www.flickr.com/photos/gastev/2630867950/
    Related to duck!

    View Slide

  27. 4. No method call

    View Slide

  28. “Message sending”

    View Slide

  29. View Slide

  30. View Slide

  31. http://www.flickr.com/photos/headlouse/1484615917/

    View Slide

  32. 5. Mixin

    View Slide

  33. Module

    View Slide

  34. Module
    • Collection of methods and constants
    • Not-instanciatable
    • But callable
    • Append features upon included

    View Slide

  35. Multiple inheritance
    is very bad

    View Slide

  36. Mixin
    • Include methods you want from another
    module
    • No limit of how many modules you include

    View Slide

  37. View Slide

  38. { 6. }
    (block)

    View Slide

  39. “Closure”

    View Slide

  40. Ruby’s Block
    • Passing a block as argument
    • Method “yield” or “call” the block
    • May passing a object as argument
    • Result from the block goes back to the
    method

    View Slide

  41. View Slide

  42. 7. We love duck
    http://www.flickr.com/photos/ymorimo/3975152607/

    View Slide

  43. Duck typing
    • If it quacks like a duck, it’s a duck!
    • Check for object’s property, not interface

    View Slide

  44. View Slide

  45. View Slide

  46. Duck Punching!

    View Slide

  47. Duck Punching
    (Monkey patch)
    • Objects and class are open
    • Add method to object even at Runtime!
    • Not really recommend, less maintainability,
    might break some stuff
    • But it’s awesome

    View Slide

  48. View Slide

  49. 8. Testing is
    FFFF**...
    (FFFFUUNNN)

    View Slide

  50. Encourage testing

    View Slide

  51. Testing ...
    • Ensure everything still works after you
    make change to something else
    • Save you ass from client’s call at 3AM
    • Test driven development
    • Write test – watch it fails – write just
    enough code to make it pass – refactor

    View Slide

  52. Testing tools
    • RSpec
    • Cucumber
    • Test::Unit
    • Rack::Test

    View Slide

  53. View Slide

  54. 9. RubyGems

    View Slide

  55. Libraries in Ruby

    View Slide

  56. http://rubygems.org

    View Slide

  57. Gem
    • Library written under Ruby or C
    • Packaged by owner and upload to
    RubyGems.org
    • Easy to install, just
    gem install gem_name

    View Slide

  58. 10. IT’S FUN!

    View Slide

  59. Question?
    Thank you!
    Prem Sichanugrist
    @sikachu
    http://sikachu.com
    3.9454 in
    Beautiful Software

    View Slide