winnipeg.rb user group - ruby intro september 2010

Upload: nathan-bertram

Post on 10-Apr-2018

216 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/8/2019 Winnipeg.rb User Group - Ruby Intro September 2010

    1/75

    Ruby from the ground

    up.

    By: Nathan Bertram

    @nathanbertram

  • 8/8/2019 Winnipeg.rb User Group - Ruby Intro September 2010

    2/75

    What Ill be talking

    about.

    1. Background & where ROR fits in.2. Basics of Ruby & interesting tidbits

    3. Other lang comparison

    4. How you can learn Ruby & Rails and its community

  • 8/8/2019 Winnipeg.rb User Group - Ruby Intro September 2010

    3/75

    Who am I?- Started out in the PHP world

    - Obsessed web standards geek.

    - Have been working professionally with Ruby &

    ROR for almost 3 years now

  • 8/8/2019 Winnipeg.rb User Group - Ruby Intro September 2010

    4/75

  • 8/8/2019 Winnipeg.rb User Group - Ruby Intro September 2010

    5/75

  • 8/8/2019 Winnipeg.rb User Group - Ruby Intro September 2010

    6/75

    New to Ruby?

  • 8/8/2019 Winnipeg.rb User Group - Ruby Intro September 2010

    7/75

    - Yukihiro Matsumoto

    I wanted a scripting language that

    was more powerful than Perl, and

    more object-oriented than Python

  • 8/8/2019 Winnipeg.rb User Group - Ruby Intro September 2010

    8/75

    Ruby ResultedA dynamic, open source programming language

    with a focus on simplicity and productivity.It has an elegant syntax

    that is natural to read and easy to write.

    via http://www.ruby-lang.org

  • 8/8/2019 Winnipeg.rb User Group - Ruby Intro September 2010

    9/75

    Ruby is an interpreted/scripting language

    - terse (concise & to the point)

    - completely object-oriented

    - standard 1.8.7 implementation written in C- wide open, even at runtime

  • 8/8/2019 Winnipeg.rb User Group - Ruby Intro September 2010

    10/75

    96 Standard Libraries

    Read/Write CSV XML YAML

    Talk to Email FTP Web

    Work with Math Templates Threads

    Tools for Debugging Docs Testing

    Tons of 3rd party open source available.

  • 8/8/2019 Winnipeg.rb User Group - Ruby Intro September 2010

    11/75

    !=

  • 8/8/2019 Winnipeg.rb User Group - Ruby Intro September 2010

    12/75

    & = FREE

  • 8/8/2019 Winnipeg.rb User Group - Ruby Intro September 2010

    13/75

    Date (Rails)

  • 8/8/2019 Winnipeg.rb User Group - Ruby Intro September 2010

    14/75

    Common Uses- Web Apps (Ruby on Rails, Sinatra)

    - One off scripts (data mining for eg.)

    - Code Generation & Image Processing- Cross platform GUI apps (WxRuby, FXRuby, Ruby

    TK)

    - Mac Desktop apps (MacRuby, Cocoa, Robot +

    JRuby)- IronRuby for .Net apps

  • 8/8/2019 Winnipeg.rb User Group - Ruby Intro September 2010

    15/75

    Some Philosophy

  • 8/8/2019 Winnipeg.rb User Group - Ruby Intro September 2010

    16/75

    OSCON 2003 - Matz: The Power and

    Philosophy ofRuby

    I want a programming to help me andothers:

    - Program better

    - Think smarter

    - Finish the task at hand quicker

    http://www.rubyist.net/~matz/slides/oscon2003/mgp00001.html

    http://rubylearning.com/blog/2010/09/28/the-ruby-movement/

  • 8/8/2019 Winnipeg.rb User Group - Ruby Intro September 2010

    17/75

    Principle of Least Surprise

  • 8/8/2019 Winnipeg.rb User Group - Ruby Intro September 2010

    18/75

    Principle of Succinctness

  • 8/8/2019 Winnipeg.rb User Group - Ruby Intro September 2010

    19/75

    Principle of Human Interface

  • 8/8/2019 Winnipeg.rb User Group - Ruby Intro September 2010

    20/75

  • 8/8/2019 Winnipeg.rb User Group - Ruby Intro September 2010

    21/75

    Show me the code.

  • 8/8/2019 Winnipeg.rb User Group - Ruby Intro September 2010

    22/75

  • 8/8/2019 Winnipeg.rb User Group - Ruby Intro September 2010

    23/75

    ( )

  • 8/8/2019 Winnipeg.rb User Group - Ruby Intro September 2010

    24/75

    Strings

  • 8/8/2019 Winnipeg.rb User Group - Ruby Intro September 2010

    25/75

    Strings

  • 8/8/2019 Winnipeg.rb User Group - Ruby Intro September 2010

    26/75

    Variables

  • 8/8/2019 Winnipeg.rb User Group - Ruby Intro September 2010

    27/75

    Methods

  • 8/8/2019 Winnipeg.rb User Group - Ruby Intro September 2010

    28/75

    Methods

  • 8/8/2019 Winnipeg.rb User Group - Ruby Intro September 2010

    29/75

    In Ruby, only false and nil are false

    0 is true "" is true

    [] is true

  • 8/8/2019 Winnipeg.rb User Group - Ruby Intro September 2010

    30/75

    Control Structures

  • 8/8/2019 Winnipeg.rb User Group - Ruby Intro September 2010

    31/75

    Control Structures

  • 8/8/2019 Winnipeg.rb User Group - Ruby Intro September 2010

    32/75

    Control Structures

  • 8/8/2019 Winnipeg.rb User Group - Ruby Intro September 2010

    33/75

    Control Structures

  • 8/8/2019 Winnipeg.rb User Group - Ruby Intro September 2010

    34/75

    Demo on Classes

  • 8/8/2019 Winnipeg.rb User Group - Ruby Intro September 2010

    35/75

    Classes

  • 8/8/2019 Winnipeg.rb User Group - Ruby Intro September 2010

    36/75

    Classes

  • 8/8/2019 Winnipeg.rb User Group - Ruby Intro September 2010

    37/75

    Inheritance

  • 8/8/2019 Winnipeg.rb User Group - Ruby Intro September 2010

    38/75

    Modules

  • 8/8/2019 Winnipeg.rb User Group - Ruby Intro September 2010

    39/75

    Constants

  • 8/8/2019 Winnipeg.rb User Group - Ruby Intro September 2010

    40/75

  • 8/8/2019 Winnipeg.rb User Group - Ruby Intro September 2010

    41/75

    Symbols are similar to strings, but are only

    allocated memory once, and are never freed.

    Great for keys, column names, and other

    strings that are repeated over and over again.

    They read well.

  • 8/8/2019 Winnipeg.rb User Group - Ruby Intro September 2010

    42/75

  • 8/8/2019 Winnipeg.rb User Group - Ruby Intro September 2010

    43/75

    Hash

  • 8/8/2019 Winnipeg.rb User Group - Ruby Intro September 2010

    44/75

    Hash

  • 8/8/2019 Winnipeg.rb User Group - Ruby Intro September 2010

    45/75

    Hash

  • 8/8/2019 Winnipeg.rb User Group - Ruby Intro September 2010

    46/75

    Hash

  • 8/8/2019 Winnipeg.rb User Group - Ruby Intro September 2010

    47/75

    Hash

  • 8/8/2019 Winnipeg.rb User Group - Ruby Intro September 2010

    48/75

    Arrays

  • 8/8/2019 Winnipeg.rb User Group - Ruby Intro September 2010

    49/75

    Arrays

  • 8/8/2019 Winnipeg.rb User Group - Ruby Intro September 2010

    50/75

    Arrays

  • 8/8/2019 Winnipeg.rb User Group - Ruby Intro September 2010

    51/75

    Regular Expressions

  • 8/8/2019 Winnipeg.rb User Group - Ruby Intro September 2010

    52/75

    Regular Expressions

  • 8/8/2019 Winnipeg.rb User Group - Ruby Intro September 2010

    53/75

    Blocks & Iterators

  • 8/8/2019 Winnipeg.rb User Group - Ruby Intro September 2010

    54/75

    Blocks & Iterators

  • 8/8/2019 Winnipeg.rb User Group - Ruby Intro September 2010

    55/75

    Blocks & Iterators

  • 8/8/2019 Winnipeg.rb User Group - Ruby Intro September 2010

    56/75

    Blocks & Iterators

  • 8/8/2019 Winnipeg.rb User Group - Ruby Intro September 2010

    57/75

    .inspect

    .methods

  • 8/8/2019 Winnipeg.rb User Group - Ruby Intro September 2010

    58/75

    Differences from C++

    No type casting

    Theres only two container types: Array

    and Hash

    Theres no type conversions, youllprobably find that they arent necessary

    Multithreading is built-in

  • 8/8/2019 Winnipeg.rb User Group - Ruby Intro September 2010

    59/75

    Differences from C++

    A unit testing lib comes standard with Ruby

    Its selfinstead ofthis

    Objects are strongly but dynamically typed.The runtime discovers at runtime if that

    method call actually works

  • 8/8/2019 Winnipeg.rb User Group - Ruby Intro September 2010

    60/75

    Differences from Java

    Theres no static type checking.Variablenames are just labels. They dont have a

    type associated with them

    There are no type declarations

    foo = Foo.new(hi) instead ofFoo foo = new Foo(hi)

    Documentation

  • 8/8/2019 Winnipeg.rb User Group - Ruby Intro September 2010

    61/75

    Documentation

    - Standard Library with Ruby contains ~ 9000 methods- Many are documented internally with a local system

    called RDOC

    - My personal favourite: http://apidock.com/- http://www.gotapi.com/ (Not just ruby, css, js, jquery,

    etc.)

    - http://rubybrain.com

    - http://stdlib.rubyonrails.org/

    - http://corelib.rubyonrails.org/

  • 8/8/2019 Winnipeg.rb User Group - Ruby Intro September 2010

    62/75

    How can I learn ruby?

  • 8/8/2019 Winnipeg.rb User Group - Ruby Intro September 2010

    63/75

  • 8/8/2019 Winnipeg.rb User Group - Ruby Intro September 2010

    64/75

    RubyKoans.comHighly recommend ifyouve programmed

    before.

    Great TDD approach with

    TestUnit and its fun!

  • 8/8/2019 Winnipeg.rb User Group - Ruby Intro September 2010

    65/75

    Whys (Poignant) Guide to Ruby

    http://mislav.uniqpath.com/poignant-guide/

  • 8/8/2019 Winnipeg.rb User Group - Ruby Intro September 2010

    66/75

    RubyQuiz.comGreat way to improve your

    existing ruby skills

    157 Quizes.

    Detailed & many solutions

    so solve the given quiz.

  • 8/8/2019 Winnipeg.rb User Group - Ruby Intro September 2010

    67/75

    http://www.TeachMeToCode.com

  • 8/8/2019 Winnipeg.rb User Group - Ruby Intro September 2010

    68/75

    - http://rubylearning.com

    - http://railscasts.com/ (FREE)

    - http://asciicasts.com/ (FREE)

    - http://peepcode.com/

    - http://envycasts.com/

  • 8/8/2019 Winnipeg.rb User Group - Ruby Intro September 2010

    69/75

    The people in this room.

    e u y a s

  • 8/8/2019 Winnipeg.rb User Group - Ruby Intro September 2010

    70/75

    e u y a s

    Community

    e u y a s

  • 8/8/2019 Winnipeg.rb User Group - Ruby Intro September 2010

    71/75

    http://railsbridge.org/projects

    #ruby and #rubyonrails on irc.freenode

    http://rubyonrails.org

    e u y a s

    Community

    http://confreaks.net/http://www.rubyinside.com/http://www.railsinside.com/

    http://railsmagazine.com

    e u y a s

  • 8/8/2019 Winnipeg.rb User Group - Ruby Intro September 2010

    72/75

    Some Bloggers I follow:

    e u y a s

    Community

    http://mislav.uniqpath.com/

    @ruby_news on twitter

    http://www.igvita.com/

    http://weblog.jamisbuck.org/

    http://blog.jayfields.com/http://www.loudthinking.com/

    http://www.hashrocket.com/blog/

    http://yehudakatz.com/

    http://pivotallabs.com/blog

  • 8/8/2019 Winnipeg.rb User Group - Ruby Intro September 2010

    73/75

    http://ruby-toolbox.com/

  • 8/8/2019 Winnipeg.rb User Group - Ruby Intro September 2010

    74/75

  • 8/8/2019 Winnipeg.rb User Group - Ruby Intro September 2010

    75/75

    Thanks!