Lock in $30 Savings on PRO—Offer Ends Soon! ⏳
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Metaprogramming Ruby
Search
Francisco Fernández Castaño
February 15, 2013
Programming
1
86
Metaprogramming Ruby
A short introduction to dynamic aspects of Ruby and Ruby Object model.
Francisco Fernández Castaño
February 15, 2013
Tweet
Share
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
87
Graph Databases
fcofdez
1
230
Graph Databases
fcofdez
3
300
Other Decks in Programming
See All in Programming
生成AIを利用するだけでなく、投資できる組織へ
pospome
2
410
チームをチームにするEM
hitode909
0
390
【卒業研究】会話ログ分析によるユーザーごとの関心に応じた話題提案手法
momok47
0
130
公共交通オープンデータ × モバイルUX 複雑な運行情報を 『直感』に変換する技術
tinykitten
PRO
0
160
re:Invent 2025 のイケてるサービスを紹介する
maroon1st
0
150
Basic Architectures
denyspoltorak
0
120
バックエンドエンジニアによる Amebaブログ K8s 基盤への CronJobの導入・運用経験
sunabig
0
170
20251212 AI 時代的 Legacy Code 營救術 2025 WebConf
mouson
0
220
AIコーディングエージェント(skywork)
kondai24
0
210
著者と進める!『AIと個人開発したくなったらまずCursorで要件定義だ!』
yasunacoffee
0
160
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
360
Full-Cycle Reactivity in Angular: SignalStore mit Signal Forms und Resources
manfredsteyer
PRO
0
180
Featured
See All Featured
Data-driven link building: lessons from a $708K investment (BrightonSEO talk)
szymonslowik
1
860
Skip the Path - Find Your Career Trail
mkilby
0
27
Fireside Chat
paigeccino
41
3.8k
What Being in a Rock Band Can Teach Us About Real World SEO
427marketing
0
150
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
9
1k
技術選定の審美眼(2025年版) / Understanding the Spiral of Technologies 2025 edition
twada
PRO
115
94k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
49
3.2k
Gemini Prompt Engineering: Practical Techniques for Tangible AI Outcomes
mfonobong
2
230
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
9
1.1k
More Than Pixels: Becoming A User Experience Designer
marktimemedia
2
260
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
37
2.7k
Done Done
chrislema
186
16k
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