1 / 65

Introduction à Ruby

Introduction à Ruby. Mardi 7 février Nicolas Ledez Architecte système Orange Business Services It&L@bs. Nicolas Ledez. Nicolas Ledez. Nicolas Ledez. Nicolas Ledez. Nicolas Ledez. IT & L@bs. Nicolas Ledez. Nicolas Ledez. Simon Courtois. Simon Courtois. CTO chez Selectra.

vui
Download Presentation

Introduction à Ruby

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Introduction à Ruby Mardi 7 févrierNicolas LedezArchitecte systèmeOrange Business Services It&L@bs

  2. Nicolas Ledez

  3. Nicolas Ledez

  4. Nicolas Ledez

  5. Nicolas Ledez

  6. Nicolas Ledez IT & L@bs

  7. Nicolas Ledez

  8. Nicolas Ledez

  9. Simon Courtois

  10. Simon Courtois CTO chez Selectra

  11. Et maintenant Ruby

  12. Ruby : l’histoire • Crée en 1995 • Inspiré de Smalltalk, Lisp, Eiffel, Ada, etc • Japonais Yukihiro Matsumoto « matz » • Index TIOBE • 12 2012 • 10 2011

  13. Japon / Lean • Toyota Production System • Gestion sans gaspillage

  14. Japon / Haïku Oh! Une luciole je voulais crier : « Regarde! » mais j'étais seul Taïg

  15. Ruby 1/3 • Interprété • Objet • Multiparadigme • Multiplateforme • Libre, gratuit, etc

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

  17. Ruby 3/3 • Héritage simple • Mixin -> « héritage multiple » • Extensions en C • Les threads indépendants de l’OS • Réflexion

  18. Virtual Machine 1/2 • Matz's Ruby Interpreter– Cruby • JRuby • IronRuby • Rubinius • MacRuby

  19. Virtual Machine 2/2 • YARV (Yetanother Ruby VM) • XRuby- rb -> Java bytecode • RubyJS - rb -> Javascript • HotRuby

  20. On commence ?

  21. Les variables • var -> variable locale • @var -> variable d'instance • @@var -> variable de classe • $var -> variable globale • Var -> constante • etc.

  22. Le langage / Procédural 1 defune_fonction puts"Salut tout le monde !" end une_fonction Salut tout le monde !

  23. Le langage / Procédural 2 defune_fonction(message) puts message end une_fonction"It's alive !" It's alive !

  24. Le langage / Objet mess1 =UneClasse.new"Salut tout le monde !" mess1.afficher_message mess1.message ="Au revoir" puts mess1.message class UneClasse attr_accessor:message definitialize(message) @message = message end defafficher_message puts @message end end Salut tout le monde ! Au revoir

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

  26. 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 ]

  27. Le langage / Dictionnaires h = Hash.new("Go Fish") h["a"]=100 h["b"]=200 h["a"]#=> 100 h["c"]#=> "Go Fish"

  28. Et on pourrait y passer des heures

  29. Classe / héritage class MyArray< Array defclean! self.eachdo |e| self.delete(e) if e % 2 end end end list = MyArray.new([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) puts list.join" " puts list.clean!.join" " puts list.join" " 1 2 3 4 5 6 7 8 9 10 2 4 6 8 10 2 4 6 8 10

  30. Classe / Monkey 1 Class Array defclean! self.eachdo |e| self.delete(e) if e % 2 end end end list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] puts list.join" " puts list.clean!.join" " puts list.join" " 1 2 3 4 5 6 7 8 9 10 2 4 6 8 10 2 4 6 8 10

  31. Classe / Monkey 2 - map Class Array defdouble self.map { |e| e * 2 } end end list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] puts list.double.join" " puts list.join" " 2 4 6 8 10 12 14 16 18 20 1 2 3 4 5 6 7 8 9 10

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

  33. Classe / Mixin class Array include MyClean end class Hash include MyClean end Module MyClean defclean! self.eachdo |e| self.delete(e) if e % 2 end end defdouble self.map{ |e| e * 2 } end End Array.new.double Hash.new.double

  34. Autour du langage

  35. Autour de Ruby / Dev • Rspec, Cucumber, Minitest, ... • Spork, Guard, ... • Bundler, RVM, Rbenv, Pik, ... • http://www.bonjourgem.com/ • +33,500 RubyGems.org

  36. Autour de Ruby / Prod • Rails, Sinatra, ... • Spork, Guard, ... • HAML, SASS, Compass, ... • Capistrano, Pupetts, Cheff, ... • 15% Ruby Github (2eme place)

  37. ORM

  38. ORM / Active record 1 classCreateTickets< ActiveRecord::Migration defchange create_table:tickets do |t| t.string:name t.text:description t.timestamps end end end

  39. ORM / Active record 2 class Ticket < ActiveRecord::Base validates_presence_of:name validates_presence_of:status belongs_to:status end

  40. ORM / DataMapper class LineItem include DataMapper::Resource property:order_id,Integer,:key=> true property:item_number,Integer, :key=> true end

  41. Framework Web

  42. Rails Uglifier Rack ERB json ActiveRecord i18n

  43. Demo Rails Par Simon Courtois

  44. Sinatra require 'sinatra' get'/hi' do "Hello World!" end

  45. Templates ERB

  46. Templates / ERB <pid="notice"><%= notice %></p> <p> <b>Name:</b> <%= @region.name %> </p> <%= link_to'Edit', edit_region_path(@region) %> | <%= link_to'Back', regions_path %>

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

  48. J’ai Windows, je fais comment

  49. Rails Installer

More Related