Cory Foy Tampa Code Camp July 15th, 2006 Ruby for C# Developers Cory Foy .
Breizh camp intro ruby
-
Upload
nicolas-ledez -
Category
Documents
-
view
395 -
download
3
description
Transcript of Breizh camp intro ruby
Jeudi 13 juinNicolas LedezArchitecte systèmeOrange Business ServicesIt&L@bs
Nicolas Ledez
<Nicolas Ledez>
Nicolas Ledez
Nicolas Ledez
Nicolas Ledez
Nicolas Ledez
IT & L@bs
Nicolas Ledez
IT & L@bs
• Ruby• Cloud• Architecture
Nicolas Ledez
Nicolas Ledez
Nicolas Ledez
Modérateur
Nicolas Ledez
</Nicolas Ledez>
<Mathias Standaert>
Développeur chez Organic Web
</Mathias Standaert>
Et maintenant 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
Toyota Production SystemGestion sans gaspillage
Japon / Lean
Oh! Une lucioleje voulais crier :
« Regarde! »mais j'étais seul
Taïg
Japon / Haïku
InterprétéObjetMultiparadigmeMultiplateformeLibre, gratuit, etc
Ruby 1/3
Ramasse-miettesGestion d'exceptionsModification du code en « live »Expressions rationnelles (Regexp)Blocs
Ruby 2/3
Héritage simpleMixin -> « héritage multiple »Extensions en CLes threads indépendants de l’OSRéflexion
Ruby 3/3
Matz's Ruby Interpreter – CrubyJRubyIronRubyRubiniusMacRuby
Virtual Machine 1/2
YARV (Yet another Ruby VM)XRuby - rb -> Java bytecodeRubyJS - rb -> JavascriptHotRuby
Virtual Machine 2/2
On commence ?
Les variables
var -> variable locale@var -> variable d'instance@@var -> variable de classe$var -> variable globaleVar -> constanteetc.
def une_fonction puts "Salut tout le monde !"end
une_fonction
Le langage / Procédural 1
Salut tout le monde !
def une_fonction(message) puts messageend
une_fonction "It's alive !"
Le langage / Procédural 2
It's alive !
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
Array.new(5, "A")a[0]['cat'] = 'feline'a[1, 2]a[1..3]a[-3, 3]
Le langage / Tableau - bases
[ 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
h = Hash.new("Go Fish")h["a"] = 100h["b"] = 200h["a"] #=> 100h["c"] #=> "Go Fish"
Le langage / Dictionnaires
Et on pourrait y passer des heures
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 " "
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 " "
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 " "
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 " "
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
Autour du langage
Rspec, Cucumber, Minitest, ...HAML, SASS, Compass, …
Autour de Ruby / Dev
Spork, Guard, ...Bundler, RVM, Rbenv, Pik, ...Vagrant
Autour de Ruby / Dev
Rails, Sinatra, ...Capistrano, Pupetts, Chef, …
Autour de Ruby / Prod
http://www.bonjourgem.com/
+40 091 RubyGems.org
Autour de Ruby / Dev
ORM
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
class Ticket < ActiveRecord::Base validates_presence_of :name validates_presence_of :status belongs_to :statusend
ORM / Active record 2
class LineItem include DataMapper::Resource
property :order_id, Integer, :key => true property :item_number, Integer, :key => trueend
ORM / DataMapper
Framework Web
Rails
Uglifier
ActiveRecordERB
i18n
Rack
json
Présentation Rails
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 / ERB
%p#notice= notice%p %b Name: = @region.name= link_to 'Edit', edit_region_path(@region)|\#{link_to 'Back', regions_path}
Templates / HAML
J’installe tout ça comment ?
Rails Installer
Windows OS X1.9 1.8
Rails Installer / DevKit
Pour Windows
JRuby
Les ressources
http://ironruby.net/try/http://tryruby.org/http://rubymonk.com/
http://railsforzombies.org/
Essayer maintenant
http://ruby.railstutorial.org/http://railscasts.com/http://www.jasimabasheer.com//posts/meta_introduction_to_ruby.html
Pour apprendre
http://nicolas.ledez.net/ @nledezhttp://www.organicweb.fr/ @organicweb
@brmichel (http://linuxfr.org/)
http://www.camilleroux.com/ @CamilleRouxhttp://matthieusegret.com/ @MatthieuSegret
A suivre
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
Conclusion
Questions ?