66

Breizh camp intro ruby

Embed Size (px)

DESCRIPTION

 

Citation preview

Page 1: Breizh camp   intro ruby
Page 2: Breizh camp   intro ruby

Jeudi 13 juinNicolas LedezArchitecte systèmeOrange Business ServicesIt&L@bs

Nicolas Ledez

Page 3: Breizh camp   intro ruby

<Nicolas Ledez>

Page 4: Breizh camp   intro ruby

Nicolas Ledez

Page 5: Breizh camp   intro ruby

Nicolas Ledez

Page 6: Breizh camp   intro ruby

Nicolas Ledez

Page 7: Breizh camp   intro ruby

Nicolas Ledez

IT & L@bs

Page 8: Breizh camp   intro ruby

Nicolas Ledez

IT & L@bs

• Ruby• Cloud• Architecture

Page 9: Breizh camp   intro ruby

Nicolas Ledez

Page 10: Breizh camp   intro ruby

Nicolas Ledez

Page 11: Breizh camp   intro ruby

Nicolas Ledez

Modérateur

Page 12: Breizh camp   intro ruby

Nicolas Ledez

Page 13: Breizh camp   intro ruby

</Nicolas Ledez>

Page 14: Breizh camp   intro ruby

<Mathias Standaert>

Page 15: Breizh camp   intro ruby

Développeur chez Organic Web

Page 16: Breizh camp   intro ruby

</Mathias Standaert>

Page 17: Breizh camp   intro ruby

Et maintenant Ruby

Page 18: Breizh camp   intro ruby

Crée en 1995 Inspiré de Smalltalk, Lisp, Eiffel, Ada, etcJaponais Yukihiro Matsumoto « matz »32% Ruby sur Github (1eme place)Index TIOBE10 201212 2011

Ruby : l’histoire

Page 19: Breizh camp   intro ruby

Toyota Production SystemGestion sans gaspillage

Japon / Lean

Page 20: Breizh camp   intro ruby

Oh! Une lucioleje voulais crier :

« Regarde! »mais j'étais seul

Taïg

Japon / Haïku

Page 21: Breizh camp   intro ruby

InterprétéObjetMultiparadigmeMultiplateformeLibre, gratuit, etc

Ruby 1/3

Page 22: Breizh camp   intro ruby

Ramasse-miettesGestion d'exceptionsModification du code en « live »Expressions rationnelles (Regexp)Blocs

Ruby 2/3

Page 23: Breizh camp   intro ruby

Héritage simpleMixin -> « héritage multiple »Extensions en CLes threads indépendants de l’OSRéflexion

Ruby 3/3

Page 24: Breizh camp   intro ruby

Matz's Ruby Interpreter – CrubyJRubyIronRubyRubiniusMacRuby

Virtual Machine 1/2

Page 25: Breizh camp   intro ruby

YARV (Yet another Ruby VM)XRuby - rb -> Java bytecodeRubyJS - rb -> JavascriptHotRuby

Virtual Machine 2/2

Page 26: Breizh camp   intro ruby

On commence ?

Page 27: Breizh camp   intro ruby

Les variables

var -> variable locale@var -> variable d'instance@@var -> variable de classe$var -> variable globaleVar -> constanteetc.

Page 28: Breizh camp   intro ruby

def une_fonction puts "Salut tout le monde !"end

une_fonction

Le langage / Procédural 1

Salut tout le monde !

Page 29: Breizh camp   intro ruby

def une_fonction(message) puts messageend

une_fonction "It's alive !"

Le langage / Procédural 2

It's alive !

Page 30: Breizh camp   intro ruby

class UneClasse attr_accessor :message

def initialize(message) @message = message end

def afficher_message puts @message endend

Le langage / Objet

Salut tout le monde !Au revoir

mess1 = UneClasse.new "Salut tout le monde !"mess1.afficher_messagemess1.message = "Au revoir"puts mess1.message

Page 31: Breizh camp   intro ruby

Array.new(5, "A")a[0]['cat'] = 'feline'a[1, 2]a[1..3]a[-3, 3]

Le langage / Tableau - bases

Page 32: Breizh camp   intro ruby

[ 1, 2, 3 ] + [ 4, 5 ]#=> [ 1, 2, 3, 4, 5 ][ 1, 1, 3, 5 ] & [ 1, 2, 3 ]#=> [ 1, 3 ][ 1, 2, 3 ] * 3#=> [ 1, 2, 3, 1, 2, 3, 1, 2, 3 ][ 1, 1, 2, 2, 3, 3, 4, 5 ] - [ 1, 2, 4 ]#=> [ 3, 3, 5 ]

Le langage / Tableau - cool

Page 33: Breizh camp   intro ruby

h = Hash.new("Go Fish")h["a"] = 100h["b"] = 200h["a"] #=> 100h["c"] #=> "Go Fish"

Le langage / Dictionnaires

Page 34: Breizh camp   intro ruby

Et on pourrait y passer des heures

Page 35: Breizh camp   intro ruby

class MyArray < Array def clean! self.each do |e| self.delete(e) if e % 2 end endend

list = MyArray.new([ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ])

Classe / héritage

1 2 3 4 5 6 7 8 9 102 4 6 8 102 4 6 8 10

puts list.join " "puts list.clean!.join " "puts list.join " "

Page 36: Breizh camp   intro ruby

Class Array def clean! self.each do |e| self.delete(e) if e % 2 end endend

list = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ]

Classe / Monkey 1

1 2 3 4 5 6 7 8 9 102 4 6 8 102 4 6 8 10

puts list.join " "puts list.clean!.join " "puts list.join " "

Page 37: Breizh camp   intro ruby

Class Array def double self.map { |e| e * 2 } endend

list = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ]

Classe / Monkey 2 - map

2 4 6 8 10 12 14 16 18 201 2 3 4 5 6 7 8 9 10

puts list.double.join " "puts list.join " "

Page 38: Breizh camp   intro ruby

Class Array def clean self.reduce([]) do |a, e| a << e unless ((e % 2) == 1) a end endend

list = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ]

Classe / Monkey 3 - reduce

2 4 6 8 101 2 3 4 5 6 7 8 9 10

puts list. clean.join " "puts list.join " "

Page 39: Breizh camp   intro ruby

Classe / Mixin

Module MyClean def clean! self.each do |e| self.delete(e) if e % 2 end end def double self.map { |e| e * 2 } endEnd

class Array include MyCleanend

class Hash include MyCleanend

Array.new.doubleHash.new.double

Page 40: Breizh camp   intro ruby

Autour du langage

Page 41: Breizh camp   intro ruby

Rspec, Cucumber, Minitest, ...HAML, SASS, Compass, …

Autour de Ruby / Dev

Page 42: Breizh camp   intro ruby

Spork, Guard, ...Bundler, RVM, Rbenv, Pik, ...Vagrant

Autour de Ruby / Dev

Page 43: Breizh camp   intro ruby

Rails, Sinatra, ...Capistrano, Pupetts, Chef, …

Autour de Ruby / Prod

Page 44: Breizh camp   intro ruby

http://www.bonjourgem.com/

+40 091 RubyGems.org

Autour de Ruby / Dev

Page 45: Breizh camp   intro ruby

ORM

Page 46: Breizh camp   intro ruby

class CreateTickets < ActiveRecord::Migration def change create_table :tickets do |t| t.string :name t.text :description

t.timestamps end endend

ORM / Active record 1

Page 47: Breizh camp   intro ruby

class Ticket < ActiveRecord::Base validates_presence_of :name validates_presence_of :status belongs_to :statusend

ORM / Active record 2

Page 48: Breizh camp   intro ruby

class LineItem include DataMapper::Resource

property :order_id, Integer, :key => true property :item_number, Integer, :key => trueend

ORM / DataMapper

Page 49: Breizh camp   intro ruby

Framework Web

Page 50: Breizh camp   intro ruby

Rails

Uglifier

ActiveRecordERB

i18n

Rack

json

Page 51: Breizh camp   intro ruby

Présentation Rails

Page 52: Breizh camp   intro ruby

Sinatra

require 'sinatra'

get '/hi' do "Hello World!"end

Page 53: Breizh camp   intro ruby

Templates

ERB

Page 54: Breizh camp   intro ruby

<p id="notice"><%= notice %></p>

<p> <b>Name:</b> <%= @region.name %></p>

<%= link_to 'Edit', edit_region_path(@region) %> |<%= link_to 'Back', regions_path %>

Templates / ERB

Page 55: Breizh camp   intro ruby

%p#notice= notice%p %b Name: = @region.name= link_to 'Edit', edit_region_path(@region)|\#{link_to 'Back', regions_path}

Templates / HAML

Page 56: Breizh camp   intro ruby

J’installe tout ça comment ?

Page 57: Breizh camp   intro ruby

Rails Installer

Windows OS X1.9 1.8

Page 58: Breizh camp   intro ruby

Rails Installer / DevKit

Pour Windows

Page 59: Breizh camp   intro ruby

JRuby

Page 60: Breizh camp   intro ruby

Les ressources

Page 61: Breizh camp   intro ruby

http://ironruby.net/try/http://tryruby.org/http://rubymonk.com/

http://railsforzombies.org/

Essayer maintenant

Page 62: Breizh camp   intro ruby

http://ruby.railstutorial.org/http://railscasts.com/http://www.jasimabasheer.com//posts/meta_introduction_to_ruby.html

Pour apprendre

Page 63: Breizh camp   intro ruby

http://nicolas.ledez.net/ @nledezhttp://www.organicweb.fr/ @organicweb

@brmichel (http://linuxfr.org/)

http://www.camilleroux.com/ @CamilleRouxhttp://matthieusegret.com/ @MatthieuSegret

A suivre

Page 64: Breizh camp   intro ruby

http://rubylive.fr/ @RubyLiveFRhttp://www.rubyfrance.org/http://www.railsfrance.org/Google groups:Rennes on RailsApéros RubyRailsfranceRuby on Rails: Core@RubyJobsFR

La communautée

Page 65: Breizh camp   intro ruby

Conclusion

Page 66: Breizh camp   intro ruby

Questions ?