Intro To Ror


Published on

Published in: Technology
  • Be the first to comment

  • Be the first to like this

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Intro To Ror

  1. 1. An Introduction to Ruby and Rails Matthew Bohnsack Wannabe Rubyist November 9 th 2005
  2. 2. Outline <ul><li>What is Ruby and why should I care? </li></ul><ul><li>What is Rails and why should I care? </li></ul><ul><li>Two must-have tools for Ruby development </li></ul><ul><li>Major Ruby features (the language in a nutshell) </li></ul><ul><li>Rails overview </li></ul><ul><li>Where to go for more information </li></ul><ul><li>Questions / Hacking </li></ul>
  3. 3. What is Ruby? Why should I care? <ul><li>What: </li></ul><ul><ul><li>The Wikipedia answer is here . </li></ul></ul><ul><ul><li>Created/lead by Matz (Japanese) </li></ul></ul><ul><ul><li>Open Source interpreted scripting language, like Perl, Python, Tcl, etc., but focused on being very object oriented, expressive, and bringing joy to programming . </li></ul></ul><ul><ul><li>Principle of least surprise </li></ul></ul><ul><li>Why: </li></ul><ul><ul><li>Productivity ideas presented in Ousterhout’s 1998 paper coming to very serious critical mass (and beyond) </li></ul></ul><ul><ul><li>Learn a new language to learn new ways of thinking about code in any language (e.g., blocks and iterators) </li></ul></ul><ul><ul><li>Joy! </li></ul></ul>
  4. 4. What is Rails? Why should I care? <ul><li>What: </li></ul><ul><ul><li>Web Framework that makes building database-driven MVC-oriented web apps easy through a template engine, ORM ( ActiveRecord ) and other best practices, such as test driven development, deployment tools, patterns, etc. </li></ul></ul><ul><ul><li>Much less complicated than J2EE solutions, but perhaps more so than PHP or Perl in cgi-bin. </li></ul></ul><ul><ul><li>Copy cats are being created in other languages: </li></ul></ul><ul><ul><ul><li>Python ( TurboGears ) </li></ul></ul></ul><ul><ul><ul><li>Perl (Maypole) </li></ul></ul></ul><ul><ul><li> + book + online screencasts + online docs & tutorials </li></ul></ul><ul><li>Why: </li></ul><ul><ul><li>I’ve been watching the world of web development since ~ 1995, and I’ve never seen anything like Rails in terms of buzz, momentum, adoption rate, etc. </li></ul></ul>
  5. 5. Must have tool #1: irb <ul><li>Interactive ruby console : </li></ul><ul><ul><li>Experiment on the fly </li></ul></ul><ul><ul><li>Tab complete object methods </li></ul></ul><ul><ul><li>… </li></ul></ul># ~/.irbrc require 'irb/completion ' use_readline=true auto_indent_mode=true
  6. 6. Must have tool #2: ri <ul><li>Console-based Ruby doc tool </li></ul>
  7. 7. Ruby in a nutshell – irb sessions follow <ul><li>Like all interpreted scripting languages, you can put code into a file, chmod +x, then just execute it. </li></ul><ul><li>But, we’ll mostly use irb sessions in this presentation… </li></ul>
  8. 8. Ruby in a nutshell – objects are everywhere <ul><li>Some languages have built-in types that aren’t objects. Not so with Ruby. Everything’s an object: </li></ul>
  9. 9. Ruby in a nutshell – objects have methods Bang on the tab key in irb to see the methods that are available for each object.
  10. 10. Ruby in a nutshell – Variables <ul><li>Local variables - start with lower case: </li></ul><ul><ul><li>foo </li></ul></ul><ul><ul><li>bar </li></ul></ul><ul><li>Global variables - start with dollar sign: </li></ul><ul><ul><li>$foo </li></ul></ul><ul><ul><li>$bar </li></ul></ul><ul><li>Constants and Classes – start with capital letter: </li></ul><ul><ul><li>CONSTANT </li></ul></ul><ul><ul><li>Class </li></ul></ul><ul><li>Instance variables – start with at sign: </li></ul><ul><ul><li>@foo </li></ul></ul><ul><ul><li>@bar </li></ul></ul><ul><li>Class variables – start with double at sign: </li></ul><ul><ul><li>@@foo </li></ul></ul><ul><ul><li>@@bar </li></ul></ul>
  11. 11. Ruby in a nutshell – Arrays
  12. 12. Ruby in a nutshell – Hashes
  13. 13. Ruby in a nutshell – Symbols <ul><li>Starts with a ‘:’ </li></ul><ul><li>Only one copy of a symbol kept in memory </li></ul>
  14. 14. Ruby in a nutshell – Blocks & Iterators
  15. 15. Ruby in a nutshell – It’s easy to build classes
  16. 16. Ruby in a nutshell – It’s fun to play with classes (like the one we just made)
  17. 17. Ruby in a nutshell – Classes are open <ul><li>Example shown here uses our Hacker class, but what happens when the whole language is open? </li></ul>
  18. 18. Ruby in a nutshell – Other notes on Classes <ul><li>Ruby only has single inheritance. This makes things simpler, but mix-ins provide much of multiple inheritance’s benefit, without the hassle. </li></ul>
  19. 19. Ruby in a nutshell – a few gotchas <ul><li>Despite the principle of least surprise: </li></ul><ul><ul><li>Zero isn’t false: </li></ul></ul><ul><ul><li>No increment operator ( foo++ ). Instead use: </li></ul></ul><ul><ul><ul><li>foo += 1 </li></ul></ul></ul><ul><ul><ul><li>foo = foo + 1 </li></ul></ul></ul>
  20. 20. Ruby in a nutshell – RubyGems <ul><li>CPAN for Ruby? </li></ul><ul><li>Examples: </li></ul><ul><ul><li>gem list </li></ul></ul><ul><ul><li>gem install redcloth --version &quot;>= 3.0.0&quot; </li></ul></ul><ul><ul><li>… </li></ul></ul><ul><li>Using gems in your program: </li></ul><ul><ul><li>require ‘rubygems’ </li></ul></ul><ul><ul><li>require ‘some_gem’ </li></ul></ul>
  21. 21. Want to learn more Ruby? <ul><li>Excellent, simple, beginner’s tutorial: </li></ul><ul><ul><li> </li></ul></ul><ul><li>Other stuff at end of talk </li></ul><ul><li>Start hacking </li></ul>
  22. 22. Quick Rails Demo – Build a TODO list application in 5 minutes <ul><li>Define database </li></ul><ul><li>rails todo </li></ul><ul><li>cd todo </li></ul><ul><li>Edit config/database.yml </li></ul><ul><li>./script/generate model Todo </li></ul><ul><li>./script/generate scaffold todo </li></ul><ul><li>Look at scaffolding </li></ul><ul><li>./script/server –b </li></ul><ul><li>Add due_date field, regenerate scaffolding, and check the results </li></ul><ul><li>./script/console </li></ul>
  23. 23. Where to go for more information <ul><li>Books: </li></ul><ul><li>Online material: </li></ul><ul><ul><li>First edition of Pickaxe online for free </li></ul></ul><ul><ul><li> / </li></ul></ul><ul><ul><li>why’s (poignant) guide to Ruby </li></ul></ul><ul><ul><li> </li></ul></ul><ul><ul><li>Rails screencast (s) </li></ul></ul><ul><ul><li>Planet Ruby on Rails </li></ul></ul>
  24. 24. The End / Questions