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
57
Thor
michelson
1
63
Other Decks in Programming
See All in Programming
Benchmark
sysong
0
250
C++20 射影変換
faithandbrave
0
530
ドメインモデリングにおける抽象の役割、tagless-finalによるDSL構築、そして型安全な最適化
knih
11
2k
datadog dash 2025 LLM observability for reliability and stability
ivry_presentationmaterials
0
110
Code as Context 〜 1にコードで 2にリンタ 34がなくて 5にルール? 〜
yodakeisuke
0
100
Beyond Portability: Live Migration for Evolving WebAssembly Workloads
chikuwait
0
390
PHPで始める振る舞い駆動開発(Behaviour-Driven Development)
ohmori_yusuke
2
180
Azure AI Foundryではじめてのマルチエージェントワークフロー
seosoft
0
130
deno-redisの紹介とJSRパッケージの運用について (toranoana.deno #21)
uki00a
0
140
ReadMoreTextView
fornewid
1
470
PHP 8.4の新機能「プロパティフック」から学ぶオブジェクト指向設計とリスコフの置換原則
kentaroutakeda
2
490
#kanrk08 / 公開版 PicoRubyとマイコンでの自作トレーニング計測装置を用いたワークアウトの理想と現実
bash0c7
1
330
Featured
See All Featured
Automating Front-end Workflow
addyosmani
1370
200k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
281
13k
Unsuck your backbone
ammeep
671
58k
Build your cross-platform service in a week with App Engine
jlugia
231
18k
How GitHub (no longer) Works
holman
314
140k
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
Measuring & Analyzing Core Web Vitals
bluesmoon
7
490
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.4k
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
7
700
The Illustrated Children's Guide to Kubernetes
chrisshort
48
50k
Designing Experiences People Love
moore
142
24k
How to train your dragon (web standard)
notwaldorf
92
6.1k
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