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
Metaprogramming Ruby
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Francisco Fernández Castaño
February 15, 2013
Programming
100
1
Share
Metaprogramming Ruby
A short introduction to dynamic aspects of Ruby and Ruby Object model.
Francisco Fernández Castaño
February 15, 2013
More Decks by Francisco Fernández Castaño
See All by Francisco Fernández Castaño
Graph Databases, a little connected tour (Codemotion Rome)
fcofdez
0
140
Bases de datos de grafos, un recorrido conectado
fcofdez
0
94
Graph Databases
fcofdez
1
240
Graph Databases
fcofdez
3
310
Other Decks in Programming
See All in Programming
ECR拡張スキャンでSBOMを収集して サプライチェーン攻撃の影響調査を 爆速で終わらせてみた
akihisaikeda
2
200
Make SRE Operations Easier with Azure SRE Agent
kkamegawa
0
890
タクシーアプリ『GO』の バックエンド開発のおける AI利活用と若者のすべて
pyama86
3
1.7k
oxlintはeslint/typescript-eslintを置き換えられるのか
shomafujita
2
250
OCRを使ってゲームのアイテムをデータ化する
kishikawakatsumi
0
120
1人1案件のプロダクトエンジニア時代に、"プロセス監督"としてチャレンジしたこと
non0113
0
330
These Five Tricks Can Make Your Apps Greener, Cheaper, & Nicer
hollycummins
0
220
Stage 3 Decorators でできること / できないこと / TSKaigi 2026
susisu
1
1.2k
GitHub Copilot CLIのいいところ
htkym
2
1.1k
プラグインで拡張される Context をtype-safe にする難しさと設計判断
kazupon
2
330
JavaDoc 再入門
nagise
0
140
Old Dog, New Tricks: The Java 25 Reinvention - JNation
bazlur_rahman
0
130
Featured
See All Featured
XXLCSS - How to scale CSS and keep your sanity
sugarenia
250
1.3M
Abbi's Birthday
coloredviolet
2
7.7k
How to Ace a Technical Interview
jacobian
281
24k
State of Search Keynote: SEO is Dead Long Live SEO
ryanjones
0
200
エンジニアに許された特別な時間の終わり
watany
107
240k
How to Think Like a Performance Engineer
csswizardry
28
2.6k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
32
3.2k
The Director’s Chair: Orchestrating AI for Truly Effective Learning
tmiket
1
180
Fantastic passwords and where to find them - at NoRuKo
philnash
52
3.7k
Learning to Love Humans: Emotional Interface Design
aarron
275
41k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
231
23k
Digital Ethics as a Driver of Design Innovation
axbom
PRO
1
290
Transcript
None
Ruby • Orientado a objetos • Lenguaje dinámico • Partes
funcionales (Bloques)
Ruby es simple en apariencia, pero complejo por dentro, como
el cuerpo humano. tratando de hacer que Ruby sea natural, no simple. Yukihiro Matsumoto 'matz'
¿Pero qué es eso del “metaprogramming”?
¿Pero qué es eso del metaprogramming? Metaprogramming is the writing
of computer programs that write or manipulate other programs (or themselves) as their data. Wikipedia
None
¿Pero qué es eso del metaprogramming? • Manejo de mensajes
cuyo destino no es conocido • Capacidad de creación y modificación de clases en runtime
None
Debemos conocer el modelo de objetos de Ruby
Debemos conocer el modelo de objetos de Ruby
en ruby todo es un objeto 2.0.0-rc2 :001 > 1.class
=> Fixnum
en ruby todo se ejecuta dentro de un objeto 2.0.0-rc2
:002 > self => main 2.0.0-rc2 :003 > class MyClass 2.0.0-rc2 :004?> self 2.0.0-rc2 :005?> end => MyClass 2.0.0-rc2 :006 > self => main 2.0.0-rc2 :007 > class MyClass 2.0.0-rc2 :008?> def test 2.0.0-rc2 :009?> self 2.0.0-rc2 :010?> end 2.0.0-rc2 :011?> def self.class_method 2.0.0-rc2 :012?> self 2.0.0-rc2 :013?> end 2.0.0-rc2 :014?> end => nil 2.0.0-rc2 :015 > MyClass.new.test => #<MyClass:0x00000002397860> 2.0.0-rc2 :016 > MyClass.class_method => MyClass
MonkeyPatches 2.0.0-rc2 :017 > class String 2.0.0-rc2 :018?> def replace
2.0.0-rc2 :019?> "dont replace" 2.0.0-rc2 :020?> end 2.0.0-rc2 :021?> end => nil 2.0.0-rc2 :022 > "stast".replace => "dont replace"
Modelo de objetos de Ruby • La keyword class solo
cambia de contexto • Las clases también son objetos de la clase Class
Modelo de objetos de Ruby class MyClass def my_method() @var
= 1 end end Obj1 = MyClass.new Obj1.my_method
Modelo de objetos de Ruby
Jerarquía de Clases class Book include Printable include Document Ancestors
# => [Book, Document, Printable, Object, Kernel, BasicObject] end
Method Lookup
None
None
Conclusiones
Cosas que me he dejado fuera
Preguntas
None