SlideShare une entreprise Scribd logo
1  sur  66
Jeudi 13 juin
Nicolas Ledez
Architecte système
Orange Business Services
It&L@bs
Nicolas Ledez
Nicolas Ledez
Nicolas Ledez
Nicolas Ledez
Nicolas Ledez
Nicolas Ledez
Nicolas Ledez
Nicolas Ledez
Nicolas Ledez
Et maintenant Ruby
Ruby : l’histoire

  Crée en 1995
   Inspiré de
  Smalltalk, Lisp, Eiffel, Ada, etc
  Japonais Yukihiro Matsumoto « matz »
  32% Ruby sur Github (1eme place)
  Index TIOBE
    10 2012
    12 2011
Japon / Lean




  Toyota Production System
  Gestion sans gaspillage
Japon / Haïku


        Oh! Une luciole
 je voulais crier : « Regarde! »
        mais j'étais seul
               Taïg
Ruby 1/3


  Interprété
  Objet
  Multiparadigme
  Multiplateforme
  Libre, gratuit, etc
Ruby 2/3



  Ramasse-miettes
  Gestion d'exceptions
  Modification du code en « live »
  Expressions rationnelles (Regexp)
  Blocs
Ruby 3/3



  Héritage simple
  Mixin -> « héritage multiple »
  Extensions en C
  Les threads indépendants de l’OS
  Réflexion
Virtual Machine 1/2

  Matz's Ruby Interpreter –
  Cruby
  JRuby
  IronRuby
  Rubinius
  MacRuby
Virtual Machine 2/2



  YARV (Yet another Ruby VM)
  XRuby - rb -> Java bytecode
  RubyJS - rb -> Javascript
  HotRuby
On commence ?
Les variables

  var -> variable locale
  @var -> variable d'instance
  @@var -> variable de
  classe
  $var -> variable globale
  Var -> constante
Le langage / Procédural 1

 def une_fonction
  puts "Salut tout le monde !"
 end

 une_fonction




 Salut tout le monde !
Le langage / Procédural 2

 def une_fonction(message)
  puts message
 end

 une_fonction "It's alive !"




 It's alive !
Le langage / Objet
 class UneClasse            mess1 = UneClasse.new "Salut
  attr_accessor :message
                            tout le monde !"
  def initialize(message)   mess1.afficher_message
   @message = message
  end                       mess1.message = "Au revoir"
                            puts mess1.message
  def afficher_message
   puts @message
  end
 end



 Salut tout le monde !
 Au revoir
Le langage / Tableau - bases


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

 [ 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 / Dictionnaires


 h = Hash.new("Go Fish")
 h["a"] = 100
 h["b"] = 200
 h["a"]       #=> 100
 h["c"]       #=> "Go Fish"
Et on pourrait y passer des heures
Classe / héritage
 class MyArray < Array
  def clean!
    self.each do |e|                 puts list.join " "
     self.delete(e) if e % 2         puts list.clean!.join "
    end
  end                                "
 end                                 puts list.join " "

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

 1 2 3 4 5 6 7 8 9 10
 2 4 6 8 10
 2 4 6 8 10
Classe / Monkey 1
 Class Array
  def clean!
   self.each do |e|                     puts list.join " "
    self.delete(e) if e % 2             puts list.clean!.join "
   end
  end                                   "
 end                                    puts list.join " "

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

 1 2 3 4 5 6 7 8 9 10
 2 4 6 8 10
 2 4 6 8 10
Classe / Monkey 2 - map

 Class Array
  def double
                                   puts list.double.join " "
   self.map { |e| e * 2 }
                                   puts list.join " "
  end
 end

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

 2 4 6 8 10 12 14 16 18 20
 1 2 3 4 5 6 7 8 9 10
Classe / Monkey 3 - reduce
 Class Array
  def clean
   self.reduce([]) do |a, e|                puts list. clean.join " "
    a << e unless ((e % 2) == 1)
    a                                       puts list.join " "
   end
  end
 end

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

 2 4 6 8 10
 1 2 3 4 5 6 7 8 9 10
Classe / Mixin

 Module MyClean               class Array
  def clean!                   include MyClean
   self.each do |e|           end
    self.delete(e) if e % 2
   end                        class Hash
  end                          include MyClean
  def double                  end
   self.map { |e| e * 2 }
  end                         Array.new.double
 End                          Hash.new.double
Autour du langage
Autour de Ruby / Dev




  Rspec, Cucumber, Minitest, ...
  HAML, SASS, Compass, …
Autour de Ruby / Dev




  Spork, Guard, ...
  Bundler, RVM, Rbenv, Pik, ...
  Vagrant
Autour de Ruby / Prod




  Rails, Sinatra, ...
  Capistrano, Pupetts, Chef, …
Autour de Ruby / Dev




  http://www.bonjourgem.com/

  +40 091 RubyGems.org
ORM / Active record 1

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

    t.timestamps
   end
  end
 end
ORM / Active record 2

 class Ticket < ActiveRecord::Base
  validates_presence_of :name
  validates_presence_of :status
  belongs_to :status
 end
ORM / DataMapper

 class LineItem
  include DataMapper::Resource

  property :order_id, Integer, :key => true
  property :item_number, Integer, :key => true
 end
Rails




                    Uglifier
                               Rack
                  ERB
   ActiveRecord                json
                        i18n
Sinatra

 require 'sinatra'

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

 <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 / HAML

 %p#notice= notice
 %p
   %b Name:
   = @region.name
 = link_to 'Edit', edit_region_path(@region)
 |
 #{link_to 'Back', regions_path}
J’installe tout ça
   comment ?
Rails Installer
Rails Installer / DevKit
JRuby
Les ressources
Essayer maintenant

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

  http://railsforzombies.org/
Pour apprendre

  http://ruby.railstutorial.org/
  http://railscasts.com/
  http://www.jasimabasheer.com//posts/meta_introd
  uction_to_ruby.html
A suivre

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

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

  http://www.camilleroux.com/ @CamilleRoux
  http://matthieusegret.com/ @MatthieuSegret
La communautée

  http://rubylive.fr/ @RubyLiveFR
  http://www.rubyfrance.org/
  http://www.railsfrance.org/
  Google groups:
  Rennes on Rails
  Apéros Ruby
  Railsfrance
  Ruby on Rails: Core
  @RubyJobsFR
Conclusion
Questions ?

Contenu connexe

Similaire à Breizh camp intro ruby

Similaire à Breizh camp intro ruby (20)

Quelle place pour le framework Rails dans le développement d'application web
Quelle place pour le framework Rails dans le développement d'application webQuelle place pour le framework Rails dans le développement d'application web
Quelle place pour le framework Rails dans le développement d'application web
 
Ruby Pour RoR
Ruby Pour RoRRuby Pour RoR
Ruby Pour RoR
 
Introduction à Sinatra
Introduction à SinatraIntroduction à Sinatra
Introduction à Sinatra
 
Cours de Matlab
Cours de MatlabCours de Matlab
Cours de Matlab
 
Mat lab1
Mat lab1Mat lab1
Mat lab1
 
Implementing a key/value store
Implementing a key/value storeImplementing a key/value store
Implementing a key/value store
 
Exploiter php 5
Exploiter php 5Exploiter php 5
Exploiter php 5
 
Trucs et astuces PHP et MySQL
Trucs et astuces PHP et MySQLTrucs et astuces PHP et MySQL
Trucs et astuces PHP et MySQL
 
PHP.pptx
PHP.pptxPHP.pptx
PHP.pptx
 
Php1
Php1Php1
Php1
 
Coursmp
CoursmpCoursmp
Coursmp
 
Redis - (nosqlfr meetup #2)
Redis - (nosqlfr meetup #2) Redis - (nosqlfr meetup #2)
Redis - (nosqlfr meetup #2)
 
Découverte du moteur de rendu du projet Spartan
Découverte du moteur de rendu du projet SpartanDécouverte du moteur de rendu du projet Spartan
Découverte du moteur de rendu du projet Spartan
 
Audits php
Audits phpAudits php
Audits php
 
Présentation Javascript à l'ESI (Alger)
Présentation Javascript à l'ESI (Alger)Présentation Javascript à l'ESI (Alger)
Présentation Javascript à l'ESI (Alger)
 
Drools
DroolsDrools
Drools
 
Flash ActionScript
Flash ActionScriptFlash ActionScript
Flash ActionScript
 
PHP - get started
PHP - get startedPHP - get started
PHP - get started
 
Future of java script web version
Future of java script web versionFuture of java script web version
Future of java script web version
 
Php seance1
Php seance1Php seance1
Php seance1
 

Breizh camp intro ruby

  • 1.
  • 2. Jeudi 13 juin Nicolas Ledez Architecte système Orange Business Services It&L@bs
  • 3.
  • 13.
  • 14.
  • 15.
  • 16.
  • 18. Ruby : l’histoire Crée en 1995 Inspiré de Smalltalk, Lisp, Eiffel, Ada, etc Japonais Yukihiro Matsumoto « matz » 32% Ruby sur Github (1eme place) Index TIOBE  10 2012  12 2011
  • 19. Japon / Lean Toyota Production System Gestion sans gaspillage
  • 20. Japon / Haïku Oh! Une luciole je voulais crier : « Regarde! » mais j'étais seul Taïg
  • 21. Ruby 1/3 Interprété Objet Multiparadigme Multiplateforme Libre, gratuit, etc
  • 22. Ruby 2/3 Ramasse-miettes Gestion d'exceptions Modification du code en « live » Expressions rationnelles (Regexp) Blocs
  • 23. Ruby 3/3 Héritage simple Mixin -> « héritage multiple » Extensions en C Les threads indépendants de l’OS Réflexion
  • 24. Virtual Machine 1/2 Matz's Ruby Interpreter – Cruby JRuby IronRuby Rubinius MacRuby
  • 25. Virtual Machine 2/2 YARV (Yet another Ruby VM) XRuby - rb -> Java bytecode RubyJS - rb -> Javascript HotRuby
  • 27. Les variables var -> variable locale @var -> variable d'instance @@var -> variable de classe $var -> variable globale Var -> constante
  • 28. Le langage / Procédural 1 def une_fonction puts "Salut tout le monde !" end une_fonction Salut tout le monde !
  • 29. Le langage / Procédural 2 def une_fonction(message) puts message end une_fonction "It's alive !" It's alive !
  • 30. Le langage / Objet class UneClasse mess1 = UneClasse.new "Salut attr_accessor :message tout le monde !" def initialize(message) mess1.afficher_message @message = message end mess1.message = "Au revoir" puts mess1.message def afficher_message puts @message end end Salut tout le monde ! Au revoir
  • 31. Le langage / Tableau - bases Array.new(5, "A") a[0]['cat'] = 'feline' a[1, 2] a[1..3] a[-3, 3]
  • 32. Le langage / Tableau - cool [ 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 ]
  • 33. Le langage / Dictionnaires h = Hash.new("Go Fish") h["a"] = 100 h["b"] = 200 h["a"] #=> 100 h["c"] #=> "Go Fish"
  • 34. Et on pourrait y passer des heures
  • 35. Classe / héritage class MyArray < Array def clean! self.each do |e| puts list.join " " self.delete(e) if e % 2 puts list.clean!.join " end end " end puts list.join " " list = MyArray.new([ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ]) 1 2 3 4 5 6 7 8 9 10 2 4 6 8 10 2 4 6 8 10
  • 36. Classe / Monkey 1 Class Array def clean! self.each do |e| puts list.join " " self.delete(e) if e % 2 puts list.clean!.join " end end " end puts list.join " " list = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ] 1 2 3 4 5 6 7 8 9 10 2 4 6 8 10 2 4 6 8 10
  • 37. Classe / Monkey 2 - map Class Array def double puts list.double.join " " self.map { |e| e * 2 } puts list.join " " end end list = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ] 2 4 6 8 10 12 14 16 18 20 1 2 3 4 5 6 7 8 9 10
  • 38. Classe / Monkey 3 - reduce Class Array def clean self.reduce([]) do |a, e| puts list. clean.join " " a << e unless ((e % 2) == 1) a puts list.join " " end end end list = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ] 2 4 6 8 10 1 2 3 4 5 6 7 8 9 10
  • 39. Classe / Mixin Module MyClean class Array def clean! include MyClean self.each do |e| end self.delete(e) if e % 2 end class Hash end include MyClean def double end self.map { |e| e * 2 } end Array.new.double End Hash.new.double
  • 41. Autour de Ruby / Dev Rspec, Cucumber, Minitest, ... HAML, SASS, Compass, …
  • 42. Autour de Ruby / Dev Spork, Guard, ... Bundler, RVM, Rbenv, Pik, ... Vagrant
  • 43. Autour de Ruby / Prod Rails, Sinatra, ... Capistrano, Pupetts, Chef, …
  • 44. Autour de Ruby / Dev http://www.bonjourgem.com/ +40 091 RubyGems.org
  • 45.
  • 46. ORM / Active record 1 class CreateTickets < ActiveRecord::Migration def change create_table :tickets do |t| t.string :name t.text :description t.timestamps end end end
  • 47. ORM / Active record 2 class Ticket < ActiveRecord::Base validates_presence_of :name validates_presence_of :status belongs_to :status end
  • 48. ORM / DataMapper class LineItem include DataMapper::Resource property :order_id, Integer, :key => true property :item_number, Integer, :key => true end
  • 49.
  • 50. Rails Uglifier Rack ERB ActiveRecord json i18n
  • 51.
  • 52. Sinatra require 'sinatra' get '/hi' do "Hello World!" end
  • 53.
  • 54. Templates / ERB <p id="notice"><%= notice %></p> <p> <b>Name:</b> <%= @region.name %> </p> <%= link_to 'Edit', edit_region_path(@region) %> | <%= link_to 'Back', regions_path %>
  • 55. Templates / HAML %p#notice= notice %p %b Name: = @region.name = link_to 'Edit', edit_region_path(@region) | #{link_to 'Back', regions_path}
  • 59. JRuby
  • 61. Essayer maintenant http://ironruby.net/try/ http://tryruby.org/ http://rubymonk.com/ http://railsforzombies.org/
  • 62. Pour apprendre http://ruby.railstutorial.org/ http://railscasts.com/ http://www.jasimabasheer.com//posts/meta_introd uction_to_ruby.html
  • 63. A suivre http://nicolas.ledez.net/ @nledez http://www.organicweb.fr/ @organicweb @brmichel (http://linuxfr.org/) http://www.camilleroux.com/ @CamilleRoux http://matthieusegret.com/ @MatthieuSegret
  • 64. La communautée http://rubylive.fr/ @RubyLiveFR http://www.rubyfrance.org/ http://www.railsfrance.org/ Google groups: Rennes on Rails Apéros Ruby Railsfrance Ruby on Rails: Core @RubyJobsFR

Notes de l'éditeur

  1. http://www.tiobe.com/index.php/content/paperinfo/tpci/index.htmlhttp://octoboard.com/public?languages=5
  2. Paradigme de programmation -&gt; style fondamentalParadigmes Objet, impératif, concurrent, fonctionnel
  3. Réflexion, -&gt; les programmes et les objets de s&apos;inspectenteux-mêmes et de se modifie