Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Ruby
Search
Miguel Michelson Martinez
August 29, 2013
Programming
1
340
Ruby
charla de ruby para continuum tour
Miguel Michelson Martinez
August 29, 2013
Tweet
Share
More Decks by Miguel Michelson Martinez
See All by Miguel Michelson Martinez
Rubymotion
michelson
0
55
Thor
michelson
1
60
Other Decks in Programming
See All in Programming
今年一番支援させていただいたのは認証系サービスでした
satoshi256kbyte
1
280
Асинхронность неизбежна: как мы проектировали сервис уведомлений
lamodatech
0
1.3k
php-conference-japan-2024
tasuku43
0
410
テストコードのガイドライン 〜作成から運用まで〜
riku929hr
6
1.3k
PSR-15 はあなたのための ものではない? - phpcon2024
myamagishi
0
360
React 19でお手軽にCSS-in-JSを自作する
yukukotani
5
530
Оптимизируем производительность блока Казначейство
lamodatech
0
870
선언형 UI에서의 상태관리
l2hyunwoo
0
250
Flatt Security XSS Challenge 解答・解説
flatt_security
0
580
Jaspr Dart Web Framework 박제창 @Devfest 2024
itsmedreamwalker
0
140
GitHub CopilotでTypeScriptの コード生成するワザップ
starfish719
26
5.8k
fs2-io を試してたらバグを見つけて直した話
chencmd
0
280
Featured
See All Featured
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
44
9.3k
Fontdeck: Realign not Redesign
paulrobertlloyd
82
5.3k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
33
2.7k
Designing for Performance
lara
604
68k
How to Think Like a Performance Engineer
csswizardry
22
1.3k
Scaling GitHub
holman
459
140k
Site-Speed That Sticks
csswizardry
2
220
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
7
550
jQuery: Nuts, Bolts and Bling
dougneiner
62
7.6k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
26
1.9k
Measuring & Analyzing Core Web Vitals
bluesmoon
5
190
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
356
29k
Transcript
CODE IS POETRY Ruby & Friends Monday, September 2, 13
MIGUEL MICHELSON https://github.com/michelson/ https://twitter.com/michelson/ RUBY DEVELOPER @ CONTINUUM Monday, September
2, 13
7 AÑOS PROGRAMANDO EN RUBY/RAILS Monday, September 2, 13
@MICHELSON Monday, September 2, 13
Monday, September 2, 13
RUBY Lenguaje OOP Permite metaprogramar sintaxis muy expresiva facil de
usar y extender Monday, September 2, 13
Yukihiro "Matz" Matsumoto Ruby es creado por Yukihiro "Matz" Matsumoto,
quien comenzó a trabajar en Ruby en 1993, y lo presentó públicamente en 1995. Monday, September 2, 13
PRINCIPIOS Monday, September 2, 13
Monday, September 2, 13
Lenguage enfocado en los humanos , no las máquinas Monday,
September 2, 13
Lenguage enfocado en los humanos , no las máquinas Diseñado
para la productividad y la diversión del desarrollador Monday, September 2, 13
“Nosotros somos los jefes. No las computadoras.” Monday, September 2,
13
Optimized for Happiness Monday, September 2, 13
7.times do puts "don’t repeat yourself" end Monday, September 2,
13
Monday, September 2, 13
IMPLEMENTACIONES Monday, September 2, 13
INTERPRETES MRI - 1.8.7, 1.9.3, 2.0 JRuby Rubinius MacRuby IronRuby
mRuby Monday, September 2, 13
DIFERENTES USOS Web Apps Desktop Apps Command Line Mobile Apps
Embebed system Monday, September 2, 13
RUBY ON RAILS Monday, September 2, 13
WEB APPS Monday, September 2, 13
Sinatra Padrino Camping Ramaze Grape Cuba Monday, September 2, 13
Rack provides a minimal interface between webservers supporting Ruby and
Ruby frameworks. Monday, September 2, 13
DESKTOP/MOBILE APPS Java Swing QT RubyMotion Ruboto Monday, September 2,
13
COMMAND LINE APPS Capistrano RAKE THOR Chef Bundler Monday, September
2, 13
RUBY Reflexivo y OO Monday, September 2, 13
REFLEXIVO Permite examinar su estado y estructura o.class? o.superclass o.instance_of?
o.is_a? o o.kind_of? o.respond_to? Name Monday, September 2, 13
OOP Define tipos de datos Crea operaciones sobre esos tipos
Instancia tipos de datos Monday, September 2, 13
METAPROGRAMACION La metaprogramación consiste en escribir programas que escriben o
manipulan otros programas (o a sí mismos) Ahorran la escritura de código Monday, September 2, 13
Monday, September 2, 13
METAPROGRAMACION User.find_by_id_or_last_name Monday, September 2, 13
ORIENTADO A OBJETOS Monday, September 2, 13
TODO ES UN OBJETO Monday, September 2, 13
PROBEMOS RUBY Monday, September 2, 13
Monday, September 2, 13
Paquetes - Gems • RubyGems • 60M+ gems cut since
July 2009. • rails, sinatra, rvm , nokogiri, etc.. etc.. Monday, September 2, 13
Instalando una gema Monday, September 2, 13
Variables human = "you" Monday, September 2, 13
Tipos de variables local = ... @instancia = .... @@clase
= .... $global = ... CONSTANTE = ... Monday, September 2, 13
Arreglos [] [1, “dos”, nil] [[“a”, 1], [“a”]] Monday, September
2, 13
Diccionarios {} { ‘a’=> 1, ‘b’=> 2} Hash.new Monday, September
2, 13
Sintaxis opcional Monday, September 2, 13
Interpolación de string Monday, September 2, 13
Interpolación de string Monday, September 2, 13
Interpolación de string Monday, September 2, 13
Interpolación de string Monday, September 2, 13
Metodos def my_method #code here .... end Monday, September 2,
13
Metodos Monday, September 2, 13
Monday, September 2, 13
Monday, September 2, 13
Monday, September 2, 13
Monday, September 2, 13
Monday, September 2, 13
Monday, September 2, 13
Monday, September 2, 13
RUBY Monday, September 2, 13
Encadenar metodos Monday, September 2, 13
Encadenar metodos Monday, September 2, 13
Encadenar metodos Monday, September 2, 13
Encadenar metodos Monday, September 2, 13
Condicionales Es como en todos los lenguajes, if, else, case
Pero ... Monday, September 2, 13
Condicionales Uso de unless OneLiner derecha a izq Ejemplo.. Monday,
September 2, 13
Condicionales Monday, September 2, 13
RUBY Monday, September 2, 13
Iteradores ary = [1,2,3,4,5] ary.each do | num | puts
num end result: 1 2 3 4 5 Monday, September 2, 13
Iteradores ary = [1,2,3,4,5] ary.each do | num | puts
num end result: 1 2 3 4 5 Monday, September 2, 13
Iteradores ary = [1,2,3,4,5] ary.each{ | num | puts num
} result: 1 2 3 4 5 Monday, September 2, 13
Iteradores ary = [1,2,3,4,5] ary.each{ | num | puts num
} result: 1 2 3 4 5 Monday, September 2, 13
Iteradores ary = [1,2,3,4,5] ary.each{ | num | puts num
} result: 1 2 3 4 5 Monday, September 2, 13
Iteradores ary = [1,2,3,4,5] ary.each{ | num | puts num
} result: 1 2 3 4 5 Monday, September 2, 13
Iteradores Enumerator Monday, September 2, 13
Iteradores Monday, September 2, 13
Iteradores • each , inject , collect , select ,
map ... Monday, September 2, 13
Iteradores • each , inject , collect , select ,
map ... • {}.each.class #=> Enumerator Monday, September 2, 13
Iteradores • each , inject , collect , select ,
map ... • {}.each.class #=> Enumerator • [].each.class #=> Enumerator Monday, September 2, 13
Select Monday, September 2, 13
Select Monday, September 2, 13
Inject Monday, September 2, 13
Inject Monday, September 2, 13
Collect Monday, September 2, 13
Collect Monday, September 2, 13
Collect Monday, September 2, 13
Collect Monday, September 2, 13
Classes class Persona attr_accessor :nombre, :apellido end Monday, September 2,
13
Classes class Persona attr_accessor :nombre, :apellido end a = Persona.new
a.nombre = “migue” #=>#<Persona:0x00718 @nombre="migue"> Monday, September 2, 13
Getters / Setters • attr_accessor # getter y setter •
attr_reader # getter • attr_writter # setter Monday, September 2, 13
attr_writer :age = Monday, September 2, 13
attr_writer If you write: attr_writer :edad That gets translated into:
def age=(value) @age = value end def age @age end Monday, September 2, 13
attr_reader :age = Monday, September 2, 13
attr_reader If you write: attr_reader :age That gets translated into:
def age @age end Monday, September 2, 13
attr_accessor :age = Monday, September 2, 13
attr_accessor If you write: attr_writer :edad That gets translated into:
def age=(value) @age = value end def age @age end Monday, September 2, 13
Constructores class Person attr_accessor :fname, :lname def initialize(fname, lname) @fname
= fname @lname = lname end end Monday, September 2, 13
Constructores matz = Person.new("Yukihiro", "Matsumoto") Monday, September 2, 13
Herencia class Animal def barf puts “barf barf!” end end
class Human < Animal end Monday, September 2, 13
Herencia class Animal def barf puts “barf barf!” end end
class Human < Animal end Monday, September 2, 13
Modulos / Mixins Monday, September 2, 13
Modulos / Mixins • Ruby no soporta herencia multiple Monday,
September 2, 13
Modulos / Mixins • Ruby no soporta herencia multiple •
Pero soporta mixins Monday, September 2, 13
Modulos module Validator def validate! puts "no actor" if @actor.nil?
end end Monday, September 2, 13
Mixin class Person attr_accessor :actor include Validator end incluye metodos
de instancia Monday, September 2, 13
class Person attr_accessor :actor include Validator end p = Person.new
p.validate! #=> “no actor” Monday, September 2, 13
Metaprogramacion • Permite la generación de metodos en tiempo de
ejecución. • Sirve para escribir código que escribe codigo que escribe código. Monday, September 2, 13
Sin metaprogramación Monday, September 2, 13
Metaprogramación • Con meta programación %w(user email food).each do |meth|
define_method(meth){ @data[meth.to_sym] } end Monday, September 2, 13
Metaprogramación • Con meta programación %w(user email food).each do |meth|
define_method(meth){ @data[meth.to_sym] } end Monday, September 2, 13
Method missing Post.find_by_title("Awesomeness!") User.find_by_email("
[email protected]
") User.find_by_email_and_login("
[email protected]
", "bob") Monday, September 2, 13
Monday, September 2, 13
Method missing class ActiveRecord::Base def method_missing(meth, *args, &block) if meth.to_s
=~ /^find_by_(.+)$/ run_find_by_method($1, *args, &block) else super end end Monday, September 2, 13
Method missing class ActiveRecord::Base def method_missing(meth, *args, &block) if meth.to_s
=~ /^find_by_(.+)$/ run_find_by_method($1, *args, &block) else super end end Monday, September 2, 13
Comunidades • Ror-es google group • Irc ruby #freenode •
http://www.ruby-forum.com/ • http://tryruby.org • railscasts.com • rubyweekly.com • rubyflow.com Monday, September 2, 13
Monday, September 2, 13
•Gracias! Monday, September 2, 13
¿Listo para probar Ruby? http://tryruby.org Monday, September 2, 13