You are on page 1of 75

Ruby from the ground up.

By: Nathan Bertram


@nathanbertram
What I’ll 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 it’s community
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
New to Ruby?
“I wanted a scripting language that was
more powerful than Perl, and more
object-oriented than Python”
- Yukihiro Matsumoto
Ruby Resulted
“A 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
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
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.


!=
& = FREE
Date (Rails)
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
Some Philosophy
OSCON 2003 - Matz: “The Power and Philosophy
of Ruby”

I want a programming to help me and others:


- 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/
“Principle of Least Surprise”
“Principle of Succinctness”
“Principle of Human Interface”
Show me the code.
( )
Strings
Strings
Variables
Methods
Methods
In Ruby, only false and nil are false
0 is true "" is true
[] is true
Control Structures
Control Structures
Control Structures
Control Structures
Demo on Classes
Classes
Classes
Inheritance
Modules
Constants
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.
Hash
Hash
Hash
Hash
Hash
Arrays
Arrays
Arrays
Regular Expressions
Regular Expressions
Blocks & Iterators
Blocks & Iterators
Blocks & Iterators
Blocks & Iterators
.inspect

.methods
Differences from C++
• No type casting
• There’s only two container types: Array and
Hash
• There’s no type conversions, you’ll probably
find that they aren’t necessary
• Multithreading is built-in
Differences from C++

• A unit testing lib comes standard with Ruby


• It’s self instead of this
• Objects are strongly but dynamically typed. The
runtime discovers at runtime if that method call
actually works
Differences from Java
• There’s no static type checking.Variable names
are just labels. They don’t have a type
associated with them
• There are no type declarations
• foo = Foo.new(“hi”) instead of
Foo foo = new Foo(“hi”)
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/
How can I learn ruby?
RubyKoans.com
Highly recommend if you’ve
programmed before.

Great TDD approach with


TestUnit and it’s fun!
Why’s (Poignant) Guide to Ruby

http://mislav.uniqpath.com/poignant-guide/
RubyQuiz.com
Great way to improve your
existing ruby skills

157 Quizes.

Detailed & many solutions so


solve the given quiz.
http://www.TeachMeToCode.com
- http://rubylearning.com
- http://railscasts.com/ (FREE)
- http://asciicasts.com/ (FREE)
- http://peepcode.com/
- http://envycasts.com/
The people in this room.
The Ruby & Rails Community
The Ruby & Rails Community
#ruby and #rubyonrails on irc.freenode

http://railsbridge.org/projects
http://rubyonrails.org
http://www.rubyinside.com/
http://www.railsinside.com/ http://confreaks.net/
http://railsmagazine.com
The Ruby & Rails Community
Some Bloggers I follow: @ruby_news on twitter
http://pivotallabs.com/blog
http://www.igvita.com/
http://mislav.uniqpath.com/
http://weblog.jamisbuck.org/
http://blog.jayfields.com/
http://www.loudthinking.com/
http://www.hashrocket.com/blog/
http://yehudakatz.com/
http://ruby-toolbox.com/
Thanks!

You might also like