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
330
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
Content Security Policy入門 セキュリティ設定と 違反レポートのはじめ方 / Introduction to Content Security Policy Getting Started with Security Configuration and Violation Reporting
uskey512
1
510
ローコードSaaSのUXを向上させるためのTypeScript
taro28
1
510
Tuning GraphQL on Rails
pyama86
2
1.2k
讓數據說話:用 Python、Prometheus 和 Grafana 講故事
eddie
0
390
subpath importsで始めるモック生活
10tera
0
240
Compose 1.7のTextFieldはPOBox Plusで日本語変換できない
tomoya0x00
0
170
Googleのテストサイズを活用したテスト環境の構築
toms74209200
0
310
macOS でできる リアルタイム動画像処理
biacco42
9
2.3k
レガシーシステムにどう立ち向かうか 複雑さと理想と現実/vs-legacy
suzukihoge
14
2.1k
AWS Lambdaから始まった Serverlessの「熱」とキャリアパス / It started with AWS Lambda Serverless “fever” and career path
seike460
PRO
1
230
ActiveSupport::Notifications supporting instrumentation of Rails apps with OpenTelemetry
ymtdzzz
1
210
Java ジェネリクス入門 2024
nagise
0
710
Featured
See All Featured
Thoughts on Productivity
jonyablonski
67
4.3k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
226
22k
How to train your dragon (web standard)
notwaldorf
88
5.7k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
47
5k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
191
16k
The MySQL Ecosystem @ GitHub 2015
samlambert
250
12k
A Tale of Four Properties
chriscoyier
156
23k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
28
9.1k
Fantastic passwords and where to find them - at NoRuKo
philnash
50
2.9k
For a Future-Friendly Web
brad_frost
175
9.4k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
131
33k
What’s in a name? Adding method to the madness
productmarketing
PRO
22
3.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