Les slides du séminaire ou cours magistral que je donne tous les ans à l'IUT Robert Schuman de Strasbourg ou dans différentes écoles d'ingénieur de Strasbourg. Les slides changent donc tous les ans, mais vous voyez l'idée.
21. Ruby class Klass def hello(*args) "Hello " + args.join(' ') end end k = Klass.new k.hello "gentle", "readers" -> "Hello gentle readers" k.send :hello, "gentle", "readers" -> "Hello gentle readers" Un langage basé sur des messages
27. Ruby class Printing def method_missing(m, *args) if (name = /^test_(.+)$/.match(m.id2name)) print name[1] end end end print = Printing.new print.test_hello -> “hello” print.test_haha -> “haha” Un langage dynamique
71. Petite parenthèse Voir REST.xls ... Verbe HTTP Url Action GET /articles Liste des articles POST /articles Création d'un article GET /articles/new Formulaire de création d'un article GET /articles/:id/edit Formulaire d'édition d'un article GET /articles/:id Visualisation d'un article PUT /articles/:id Mise à jour d'un article DELETE /articles/:id Suppression d'un article
96. Active Record CREATE TABLE products ( id int(11) NOT NULL auto_increment, name varchar(255), PRIMARY KEY (id) ); class Product < ActiveRecord::Base end my_product = Product.new my_product.name = “Pipo” my_product.save my_product = Product.new({ “name” => “Molo” }) my_product = Product.find(:first) Fonctionnement de base
97. Active Record CREATE TABLE products ( id int(11) NOT NULL auto_increment, customer_id int(11) NOT NULL, name varchar(255), PRIMARY KEY (id) ); CREATE TABLE customers ( id int(11) NOT NULL auto_increment, name varchar(255), PRIMARY KEY (id) ); class Product < ActiveRecord::Base belongs_to :customer end class Customer < ActiveRecord::Base has_many :products end customer = Customer.new customer.name = “IBM” product = Product.new product.name = “pipo” customer.products << product customer.products.size Support des relations
111. Action Pack Routage d'url Verbe HTTP Url Action Helper GET /articles index articles_path POST /articles create articles_path GET /articles/new new new_article_path GET /articles/:id/edit edit edit_article_path(product) GET /articles/:id show product_path(product) PUT /articles/:id update product_path(product) DELETE /articles/:id destroy product_path(product)