INTRODUCTION TO RUBY PETER COOPER If you get bored... - - PowerPoint PPT Presentation

introduction to ruby
SMART_READER_LITE
LIVE PREVIEW

INTRODUCTION TO RUBY PETER COOPER If you get bored... - - PowerPoint PPT Presentation

INTRODUCTION TO RUBY PETER COOPER If you get bored... www.petercooper.co.uk www.rubyinside.com www.ruby-lang.org THE ANECDOTE THE DOWNSIDES THE LANGUAGE THE COMMUNITY THE LIBRARIES THE APPLICATIONS THE IMPLEMENTATIONS THE QUESTIONS


slide-1
SLIDE 1

INTRODUCTION TO RUBY

PETER COOPER If you get bored... www.petercooper.co.uk www.rubyinside.com www.ruby-lang.org

slide-2
SLIDE 2

THE ANECDOTE THE DOWNSIDES THE LANGUAGE THE COMMUNITY THE LIBRARIES THE APPLICATIONS THE IMPLEMENTATIONS THE QUESTIONS

slide-3
SLIDE 3

Paul Graham

slide-4
SLIDE 4

THE ANECDOTE THE DOWNSIDES THE LANGUAGE THE COMMUNITY THE LIBRARIES THE APPLICATIONS THE IMPLEMENTATIONS THE QUESTIONS

slide-5
SLIDE 5

THE DOWNSIDES

slide-6
SLIDE 6

THE DOWNSIDES

SLOW

slide-7
SLIDE 7

THE DOWNSIDES

UNPOPULAR

slide-8
SLIDE 8

Java C

Visual Basic PHP

C++ Perl

Python

C#

Delphi Ruby

JavaScript D

PL/SQL SAS COBOL

slide-9
SLIDE 9

THE ANECDOTE THE DOWNSIDES THE LANGUAGE THE COMMUNITY THE LIBRARIES THE APPLICATIONS THE IMPLEMENTATIONS THE QUESTIONS

slide-10
SLIDE 10

Matz

slide-11
SLIDE 11

Matz

slide-12
SLIDE 12

Installing Ruby

slide-13
SLIDE 13

Installing Ruby

slide-14
SLIDE 14

IRB == Interactive RuBy

slide-15
SLIDE 15

tryruby.hobix.com

slide-16
SLIDE 16

IRB == Interactive RuBy

slide-17
SLIDE 17

Expressions

slide-18
SLIDE 18

Objects and Methods

slide-19
SLIDE 19

Method List

>> “this is a test”.methods

=> ["%", "select", "[]=", "inspect", "<<", "each_byte", "method", "clone", "gsub", "casecmp", "public_methods", "to_str", "partition", "tr_s", "empty?", "instance_variable_defined?", "tr!", "gem", "freeze", "equal?", "rstrip", "*", "match", "grep", "chomp!", "+", "next!", "swapcase", "ljust", "to_i", "swapcase!", "respond_to?", "methods", "upto", "between?", "reject", "sum", "hex", "dup", "insert", "reverse!", "chop", "instance_variables", "delete", "dump", "__id__", "tr_s!", "concat", "member?", "object_id", "succ", "find", "eql?", "require", "each_with_index", "strip!", "id", "rjust", "to_f", "send", "singleton_methods", "index", "collect", "oct", "all?", "slice", "taint", "length", "entries", "chomp", "instance_variable_get", "frozen?", "upcase", "sub!", "squeeze", "include?", "instance_of?", "__send__", "upcase!", "crypt", "delete!", "detect", "to_a", "unpack", "zip", "lstrip!", "type", "center", "<", "instance_eval", "protected_methods", "map", "<=>", "rindex", "display", "any?", "==", ">", "split", "===", "strip", "size", "sort", "instance_variable_set", "gsub!", "count", "succ!", "downcase", "min", "extend", "kind_of?", "squeeze!", "downcase!", "intern", ">=", "next", "find_all", "to_s", "<=", "each_line", "each", "rstrip!", "class", "slice!", "hash", "sub", "private_methods", "tainted?", "replace", "inject", "=~", "tr", "reverse", "untaint", "nil?", "sort_by", "lstrip", "to_sym", "capitalize", "max", "chop!", "is_a?", "capitalize!", "scan", "[]"]

slide-20
SLIDE 20

Hashes and Symbols

fred = { :name => “Fred”, :age => 76, :occupation => :janitor } fred[:name] => “Fred” fred[:age] => 76

slide-21
SLIDE 21

Hashes and Symbols

fred = { :name => “Fred”, :age => 76, :occupation => :janitor } fred[:name] => “Fred” fred[:age] => 76 people = [ { :name => “Fred”, :age => 76 }, { :name => “Maggie”, :age => 22 }, { :name => “Laura”, :age => 24 } ] people.size => 3 people[1] => { :name => “Maggie”, :age => 22 }

slide-22
SLIDE 22

Iterators

names = %w(Fred Bert Laura Gus Waldo) names.each { |name| puts name }

slide-23
SLIDE 23

Iterators

names = %w(Fred Bert Laura Gus Waldo) names.each { |name| puts name } Fred Bert Laura Gus Waldo

slide-24
SLIDE 24

Iterators

names = %w(Fred Bert Laura Gus Waldo) names.each do |name| puts name end

slide-25
SLIDE 25

Iterators

1.upto(8) do |i| puts i end

slide-26
SLIDE 26

Iterators

1.upto(8) do |i| puts i end 1 2 3 4 5 6 7 8

slide-27
SLIDE 27

Iterators

[1, 2, 3, 4, 5].map do |number| number * 2 end => [2, 4, 6, 8, 10]

slide-28
SLIDE 28

Iterators

[1, 2, 3, 4, 5].map do |number| number * 2 end => [2, 4, 6, 8, 10] [1, 2, 3, 4, 5].map do |number| number.to_s * 2 end => [“11”, “22”, “33”, “44”, “55”]

slide-29
SLIDE 29

Classes

class Person end

me = Person.new me.class => Person you = Person.new you.class => Person

slide-30
SLIDE 30

Classes

class Person attr_accessor :name, :age end

me = Person.new me.name = “Peter” me.age = 26 fred = Person.new fred.name = “Fred” fred.age = 77 fred.age + me.age => 103

slide-31
SLIDE 31

class Person def year_born=(year) @age = Time.now.year - year end def age return @age end end me = Person.new me.year_born = 1981 me.age => 27

Classes

slide-32
SLIDE 32

Classes

class Person def year_born=(year) @age = Time.now.year - year end def age @age end end me = Person.new me.year_born = 1981 me.age => 27

slide-33
SLIDE 33

Classes

class Person attr_reader :age def year_born=(year) @age = Time.now.year - year end end me = Person.new me.year_born = 1981 me.age => 27

slide-34
SLIDE 34

STOP

slide-35
SLIDE 35

require 'rubygems' require 'png' def f(x, y) ( (x ^ y) & ((y - 350) >> 3) ) ** 2 end canvas = PNG::Canvas.new(500, 500) 0.upto(499) do |y| 0.upto(499) do |x| if ((f(x, y) >> 12) & 1) == 1 canvas[x, 499 - y] = PNG::Color::Black else canvas[x, 499 - y] = PNG::Color::White end end end png = PNG.new(canvas) png.save 'pattern.png'

slide-36
SLIDE 36

require 'rubygems' require 'png' def f(x, y) ( (x ^ y) & ((y - 350) >> 3) ) ** 2 end canvas = PNG::Canvas.new(500, 500) 0.upto(499) do |y| 0.upto(499) do |x| if ((f(x, y) >> 12) & 1) == 1 canvas[x, 499 - y] = PNG::Color::Black else canvas[x, 499 - y] = PNG::Color::White end end end png = PNG.new(canvas) png.save 'pattern.png'

slide-37
SLIDE 37

require 'rubygems' require 'png' def f(x, y) ( (x ^ y) & ((y - 350) >> 3) ) ** 2 end canvas = PNG::Canvas.new(500, 500) 0.upto(499) do |y| 0.upto(499) do |x| if ((f(x, y) >> 12) & 1) == 1 canvas[x, 499 - y] = PNG::Color::Black else canvas[x, 499 - y] = PNG::Color::White end end end png = PNG.new(canvas) png.save 'pattern.png'

slide-38
SLIDE 38

require 'rubygems' require 'png' def f(x, y) ( (x ^ y) & ((y - 350) >> 3) ) ** 2 end canvas = PNG::Canvas.new(500, 500) 0.upto(499) do |y| 0.upto(499) do |x| if ((f(x, y) >> 12) & 1) == 1 canvas[x, 499 - y] = PNG::Color::Black else canvas[x, 499 - y] = PNG::Color::White end end end png = PNG.new(canvas) png.save 'pattern.png'

slide-39
SLIDE 39

require 'rubygems' require 'png' def f(x, y) ( (x ^ y) & ((y - 350) >> 3) ) ** 2 end canvas = PNG::Canvas.new(500, 500) 0.upto(499) do |y| 0.upto(499) do |x| if ((f(x, y) >> 12) & 1) == 1 canvas[x, 499 - y] = PNG::Color::Black else canvas[x, 499 - y] = PNG::Color::White end end end png = PNG.new(canvas) png.save 'pattern.png'

slide-40
SLIDE 40

require 'rubygems' require 'png' def f(x, y) ( (x ^ y) & ((y - 350) >> 3) ) ** 2 end canvas = PNG::Canvas.new(500, 500) 0.upto(499) do |y| 0.upto(499) do |x| if ((f(x, y) >> 12) & 1) == 1 canvas[x, 499 - y] = PNG::Color::Black else canvas[x, 499 - y] = PNG::Color::White end end end png = PNG.new(canvas) png.save 'pattern.png'

slide-41
SLIDE 41

require 'rubygems' require 'png' def f(x, y) ( (x ^ y) & ((y - 350) >> 3) ) ** 2 end canvas = PNG::Canvas.new(500, 500) 0.upto(499) do |y| 0.upto(499) do |x| if ((f(x, y) >> 12) & 1) == 1 canvas[x, 499 - y] = PNG::Color::Black else canvas[x, 499 - y] = PNG::Color::White end end end png = PNG.new(canvas) png.save 'pattern.png'

slide-42
SLIDE 42

require 'rubygems' require 'png' def f(x, y) ( (x ^ y) & ((y - 350) >> 3) ) ** 2 end canvas = PNG::Canvas.new(500, 500) 0.upto(499) do |y| 0.upto(499) do |x| if ((f(x, y) >> 12) & 1) == 1 canvas[x, 499 - y] = PNG::Color::Black else canvas[x, 499 - y] = PNG::Color::White end end end png = PNG.new(canvas) png.save 'pattern.png'

slide-43
SLIDE 43

require 'rubygems' require 'png' def f(x, y) ( (x ^ y) & ((y - 350) >> 3) ) ** 2 end canvas = PNG::Canvas.new(500, 500) 0.upto(499) do |y| 0.upto(499) do |x| if ((f(x, y) >> 12) & 1) == 1 canvas[x, 499 - y] = PNG::Color::Black else canvas[x, 499 - y] = PNG::Color::White end end end png = PNG.new(canvas) png.save 'pattern.png'

slide-44
SLIDE 44

require 'rubygems' require 'png' def f(x, y) ( (x ^ y) & ((y - 350) >> 3) ) ** 2 end canvas = PNG::Canvas.new(500, 500) 0.upto(499) do |y| 0.upto(499) do |x| if ((f(x, y) >> 12) & 1) == 1 canvas[x, 499 - y] = PNG::Color::Black else canvas[x, 499 - y] = PNG::Color::White end end end png = PNG.new(canvas) png.save 'pattern.png'

slide-45
SLIDE 45

require 'rubygems' require 'png' def f(x, y) ( (x ^ y) & ((y - 350) >> 3) ) ** 2 end canvas = PNG::Canvas.new(500, 500) 0.upto(499) do |y| 0.upto(499) do |x| if ((f(x, y) >> 12) & 1) == 1 canvas[x, 499 - y] = PNG::Color::Black else canvas[x, 499 - y] = PNG::Color::White end end end png = PNG.new(canvas) png.save 'pattern.png'

slide-46
SLIDE 46
slide-47
SLIDE 47

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

slide-48
SLIDE 48

THE ANECDOTE THE DOWNSIDES THE LANGUAGE THE COMMUNITY THE LIBRARIES THE APPLICATIONS THE IMPLEMENTATIONS THE QUESTIONS

slide-49
SLIDE 49

Events

slide-50
SLIDE 50

Events

slide-51
SLIDE 51

User Groups

slide-52
SLIDE 52

User Groups

slide-53
SLIDE 53

Books

slide-54
SLIDE 54

Books

slide-55
SLIDE 55

Dave Thomas

slide-56
SLIDE 56

Books

slide-57
SLIDE 57

Books

slide-58
SLIDE 58

Books

slide-59
SLIDE 59

Books

slide-60
SLIDE 60

Books

slide-61
SLIDE 61

Books

slide-62
SLIDE 62

Books

slide-63
SLIDE 63

Training

slide-64
SLIDE 64

Training

slide-65
SLIDE 65

Web 2.0 Online Chat Screencasts Blogs

slide-66
SLIDE 66

rubyinside.com

slide-67
SLIDE 67

rubycorner.com

slide-68
SLIDE 68

peepcode.com

slide-69
SLIDE 69

The People

slide-70
SLIDE 70

THE ANECDOTE THE DOWNSIDES THE LANGUAGE THE COMMUNITY THE LIBRARIES THE APPLICATIONS THE IMPLEMENTATIONS THE QUESTIONS

slide-71
SLIDE 71

RUBY GEMS

slide-72
SLIDE 72

gem install rails

slide-73
SLIDE 73

Installing a Gem

slide-74
SLIDE 74

Using a Gem

require 'rubygems' require 'chronic' Time.now #=> Tue Apr 01 11:30:00 CET 2008 Chronic.parse('tomorrow') #=> Wed Apr 02 12:00:00 +0100 2008 Chronic.parse('last monday') #=> Mon Mar 31 12:00:00 +0100 2008 Chronic.parse('next monday at 5pm') #=> Mon Apr 7 17:00:00 +0100 2008

slide-75
SLIDE 75

Hpricot

doc = Hpricot(

  • pen("http://redhanded.hobix.com/index.html")

) puts doc.search("p").size ( doc / "#sidebar" ).remove puts doc

http://code.whytheluckystiff.net/hpricot

1 2 3 4

slide-76
SLIDE 76

Gruff

http://nubyonrails.com/pages/gruff

require 'gruff' g = Gruff::Line.new g.title = "My Fruity Graph" g.data("Apples", [1, 2, 3, 4, 4, 3]) g.data("Oranges", [4, 8, 7, 9, 8, 9]) g.data("Peaches", [9, 9, 10, 8, 7, 9]) g.labels = {0 => '2003', 2 => '2005', 4 => '2007'} g.write('my_fruity_graph.png')

slide-77
SLIDE 77
slide-78
SLIDE 78

Classifier

require 'classifier' filter = Classifier::Bayes.new(:spam, :ham) filter.train :spam, 'Free viagra!' filter.train :spam, 'Free credit card offer!' filter.train :spam, 'Enhance your anatomy' filter.train :ham, 'URGENT. Your server is down.' filter.train :ham, 'Your Amazon.com Order' filter.train :ham, 'E-mail from mom' filter.classify('Your Play.com Order') # => 'Ham' filter.classify('Free love tonight') # => 'Spam'

http://classifier.rubyforge.org/

1 2 3 4 5

slide-79
SLIDE 79

http://classifier.rubyforge.org/

slide-80
SLIDE 80

Libraries

Word stemming Image manipulation 3D graphics 2D graphics Physics Bioinformatics E-mail generation Bayes classification SQL generation Text language detection Language parsing Web application frameworks OS integration HTTP servers Other network daemons Credit card validation Payment gateway integration CAPTCHAs RSS feed processing Caching and memoization Graphing Web crawling Gem generation GUI widget library bridges Report generation Unicode handling Core Ruby improvements Text manipulation Content indexing Search

http://rubyforge.org/

slide-81
SLIDE 81

THE ANECDOTE THE DOWNSIDES THE LANGUAGE THE COMMUNITY THE LIBRARIES THE APPLICATIONS THE IMPLEMENTATIONS THE QUESTIONS

slide-82
SLIDE 82

Rak

http://rak.rubyforge.org/

slide-83
SLIDE 83

Sup

http://sup.rubyforge.org/

slide-84
SLIDE 84

SwitchPipe

http://switchpipe.org/

slide-85
SLIDE 85

FreeRIDE

http://freeride.rubyforge.org/

slide-86
SLIDE 86

Mondrian IDE

http://www.mondrian-ide.com/

slide-87
SLIDE 87

RubyCocoa

slide-88
SLIDE 88

GitNub

http://github.com/Caged/gitnub/wikis/home

slide-89
SLIDE 89

Captain Ruby

example with the Gosu library

slide-90
SLIDE 90

Captain Ruby

example with the Gosu library

slide-91
SLIDE 91

Chipmunk Physics

slide-92
SLIDE 92

Ogre

slide-93
SLIDE 93

THE ANECDOTE THE DOWNSIDES THE LANGUAGE THE COMMUNITY THE LIBRARIES THE APPLICATIONS THE IMPLEMENTATIONS THE QUESTIONS

slide-94
SLIDE 94

Rubinius Iron Ruby JRuby MRI

slide-95
SLIDE 95

THE ANECDOTE THE DOWNSIDES THE LANGUAGE THE COMMUNITY THE LIBRARIES THE APPLICATIONS THE IMPLEMENTATIONS THE QUESTIONS

slide-96
SLIDE 96

QUESTIONS?

If you get bored... www.rubyinside.com www.petercooper.co.uk

slide-97
SLIDE 97

THE END

If you get bored... www.rubyinside.com www.petercooper.co.uk