SlideShare a Scribd company logo
REFLEXIVE METAPROGRAMMING IN RUBY

TUTORIAL PRESENTATION

H. Conrad Cunningham
Department of Computer and Information Science
University of Mississippi
University, MS 38677
(662) 915-5358
cunningham@cs.olemiss.edu

ABSTRACT
Ruby is an interpreted, dynamically typed, object-oriented application programming language [10]. It has
been in existence for more than a decade, but in the past three years interest in the Ruby language and the
programming styles it enables [2] has exploded in the practitioner community [8, 9]. Much of the explosive
growth in interest has been because of the advent of the Ruby on Rails Web application framework [7, 11].

Ruby on Rails is essentially a domain-specific language (DSL) [1, 6] for web applications. It is
implemented as an internal (or embedded) DSL [4, 5] using Ruby’s flexible syntax and extensive reflexive
metaprogramming facilities [3]. Reflexive metaprogramming is the capability of a program to both inspect
and change its own program structures [12]. It has long been a staple of languages such as Smalltalk and
Lisp, but the recent interest in Ruby has renewed interest in metaprogramming and in techniques like
internal DSLs.

This tutorial does not concern itself with Ruby on Rails, but, instead, focuses on the Ruby features that
make Rails possible. It examines Ruby with an emphasis on the language’s distinctive reflexive
metaprogramming facilities and techniques. These include the ability to query a class to determine what its
methods, instance variables, and superclasses are—facilities that exist in mainstream languages like Java.
Ruby also includes more exotic seeming facilities such as the ability to intercept calls to missing methods,
to define new classes and methods dynamically, and to evaluate strings as Ruby code. The tutorial uses
internal DSLs to motivate the utility of these language features.

PRESENTER
H. Conrad Cunningham is Professor and Chair of Computer and Information Science at the University of
Mississippi (Ole Miss).      His professional interests include software architecture, programming
methodology, programming languages, and concurrent and distributed computing. He has a BS degree in
mathematics from Arkansas State University and MS and DSc degrees in computer science from
Washington University in St. Louis. Cunningham has taught courses on software engineering, software
architecture, software components, object-oriented programming, and functional programming. In the Fall
2006 semester, he taught a graduate course that included considerable content on Ruby programming,
including its functional programming and reflexive metaprogramming features, and on domain-specific
languages.

REFERENCES
[1] Bentley, J., Programming pearls: Little languages, Communications of the ACM, 29 (8), 711-721, 1986.
[2] Carlson, L., Richardson, L., Ruby Cookbook, O’Reilly, 2006
[3] Freeze, J., Creating DSLs with Ruby, Artima Developer,
http://www.artima.com/rubycs/articles/ruby_as_dsl.html, March 2006.
[4] Fowler, M., Language workbenches: The killer-app for domain specific languages?
http://www.martinfowler.com/articles/languageWorkbench.html, June 2005.
[5] Fowler, M., Generating code for DSLs, http://www.martinfowler.com/articles/codeGenDsl.html, June
2005.
[6] Mernik, M., Heering, J., Sloane, A. M., When and how to develop domain-specific languages, ACM
Computing Surveys, 37 (4), 316-344, 2005.
[7] Ruby on Rails Project, http://www.rubyonrails.org, accessed December 2, 2006.
[8] Tate, B., Beyond Java, O’Reilly, 2005.
[9] Tate, B., From Java to Ruby: Things Every Manager Should Know, Pragmatic Bookshelf, 2006.
[10] Thomas, D., Fowler, C., Hunt, A., Programming Ruby: The Pragmatic Programmers' Guide, Second
Edition, Pragmatic Bookshelf, 2005.
[11] Thomas, D., Heinemeier Hansson, D., Agile Web Development with Rails, Second Edition, Pragmatic
Bookshelf, 2006.
[12] Wikipedia: The Free Encyclopedia, Metaprogramming,
http://en.wikipedia.org/wiki/Metaprogramming, accessed December 2, 2006.

More Related Content

PDF
Ruby Metaprogramming 08
PDF
DSL Construction with Ruby - ThoughtWorks Masterclass Series 2009
PDF
Metaprogramming in Ruby
PDF
Ruby Metaprogramming - OSCON 2008
PDF
Ruby an overall approach
PDF
Ruby seen from a C# developer
PDF
Ruby seen by a C# developer
PDF
Agile DSL Development in Ruby
Ruby Metaprogramming 08
DSL Construction with Ruby - ThoughtWorks Masterclass Series 2009
Metaprogramming in Ruby
Ruby Metaprogramming - OSCON 2008
Ruby an overall approach
Ruby seen from a C# developer
Ruby seen by a C# developer
Agile DSL Development in Ruby

Similar to RubyMetaprogramming (20)

KEY
Ruby on Rails Training - Module 1
KEY
Introduction to Ruby
PDF
DSL Construction rith Ruby
PPT
Java, Ruby & Rails
PPTX
Why Ruby?
PDF
Os Alrubaie Ruby
PPTX
Simple Ruby DSL Techniques: Big Project Impact!
PDF
Ruby — An introduction
PDF
Ruby.new @ VilniusRB
PPTX
Why ruby
PPTX
Ruby for .NET developers
ZIP
Meta Programming in Ruby - Code Camp 2010
PPTX
Day 1 - Intro to Ruby
PDF
FGCU Camp Talk
PDF
IJTC%202009%20JRuby
PDF
IJTC%202009%20JRuby
PDF
Introduction to Ruby & Modern Programming
PPT
Feelin' Groovy: An Afternoon of Reflexive Metaprogramming
ODP
PPT
WorkinOnTheRailsRoad
Ruby on Rails Training - Module 1
Introduction to Ruby
DSL Construction rith Ruby
Java, Ruby & Rails
Why Ruby?
Os Alrubaie Ruby
Simple Ruby DSL Techniques: Big Project Impact!
Ruby — An introduction
Ruby.new @ VilniusRB
Why ruby
Ruby for .NET developers
Meta Programming in Ruby - Code Camp 2010
Day 1 - Intro to Ruby
FGCU Camp Talk
IJTC%202009%20JRuby
IJTC%202009%20JRuby
Introduction to Ruby & Modern Programming
Feelin' Groovy: An Afternoon of Reflexive Metaprogramming
WorkinOnTheRailsRoad
Ad

More from tutorialsruby (20)

PDF
<img src="../i/r_14.png" />
PDF
TopStyle Help & <b>Tutorial</b>
PDF
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting <b>...</b>
PDF
<img src="../i/r_14.png" />
PDF
<img src="../i/r_14.png" />
PDF
Standardization and Knowledge Transfer – INS0
PDF
xhtml_basics
PDF
xhtml_basics
PDF
xhtml-documentation
PDF
xhtml-documentation
PDF
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
PDF
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
PDF
HowTo_CSS
PDF
HowTo_CSS
PDF
BloggingWithStyle_2008
PDF
BloggingWithStyle_2008
PDF
cascadingstylesheets
PDF
cascadingstylesheets
<img src="../i/r_14.png" />
TopStyle Help & <b>Tutorial</b>
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting <b>...</b>
<img src="../i/r_14.png" />
<img src="../i/r_14.png" />
Standardization and Knowledge Transfer – INS0
xhtml_basics
xhtml_basics
xhtml-documentation
xhtml-documentation
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
HowTo_CSS
HowTo_CSS
BloggingWithStyle_2008
BloggingWithStyle_2008
cascadingstylesheets
cascadingstylesheets
Ad

Recently uploaded (20)

PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Machine learning based COVID-19 study performance prediction
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPT
Teaching material agriculture food technology
PDF
Empathic Computing: Creating Shared Understanding
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
KodekX | Application Modernization Development
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PPTX
Spectroscopy.pptx food analysis technology
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Encapsulation theory and applications.pdf
PDF
Chapter 3 Spatial Domain Image Processing.pdf
Mobile App Security Testing_ A Comprehensive Guide.pdf
Per capita expenditure prediction using model stacking based on satellite ima...
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Machine learning based COVID-19 study performance prediction
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Teaching material agriculture food technology
Empathic Computing: Creating Shared Understanding
MIND Revenue Release Quarter 2 2025 Press Release
“AI and Expert System Decision Support & Business Intelligence Systems”
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
20250228 LYD VKU AI Blended-Learning.pptx
Encapsulation_ Review paper, used for researhc scholars
KodekX | Application Modernization Development
Advanced methodologies resolving dimensionality complications for autism neur...
Spectroscopy.pptx food analysis technology
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Encapsulation theory and applications.pdf
Chapter 3 Spatial Domain Image Processing.pdf

RubyMetaprogramming

  • 1. REFLEXIVE METAPROGRAMMING IN RUBY TUTORIAL PRESENTATION H. Conrad Cunningham Department of Computer and Information Science University of Mississippi University, MS 38677 (662) 915-5358 cunningham@cs.olemiss.edu ABSTRACT Ruby is an interpreted, dynamically typed, object-oriented application programming language [10]. It has been in existence for more than a decade, but in the past three years interest in the Ruby language and the programming styles it enables [2] has exploded in the practitioner community [8, 9]. Much of the explosive growth in interest has been because of the advent of the Ruby on Rails Web application framework [7, 11]. Ruby on Rails is essentially a domain-specific language (DSL) [1, 6] for web applications. It is implemented as an internal (or embedded) DSL [4, 5] using Ruby’s flexible syntax and extensive reflexive metaprogramming facilities [3]. Reflexive metaprogramming is the capability of a program to both inspect and change its own program structures [12]. It has long been a staple of languages such as Smalltalk and Lisp, but the recent interest in Ruby has renewed interest in metaprogramming and in techniques like internal DSLs. This tutorial does not concern itself with Ruby on Rails, but, instead, focuses on the Ruby features that make Rails possible. It examines Ruby with an emphasis on the language’s distinctive reflexive metaprogramming facilities and techniques. These include the ability to query a class to determine what its methods, instance variables, and superclasses are—facilities that exist in mainstream languages like Java. Ruby also includes more exotic seeming facilities such as the ability to intercept calls to missing methods, to define new classes and methods dynamically, and to evaluate strings as Ruby code. The tutorial uses internal DSLs to motivate the utility of these language features. PRESENTER H. Conrad Cunningham is Professor and Chair of Computer and Information Science at the University of Mississippi (Ole Miss). His professional interests include software architecture, programming methodology, programming languages, and concurrent and distributed computing. He has a BS degree in mathematics from Arkansas State University and MS and DSc degrees in computer science from Washington University in St. Louis. Cunningham has taught courses on software engineering, software architecture, software components, object-oriented programming, and functional programming. In the Fall 2006 semester, he taught a graduate course that included considerable content on Ruby programming, including its functional programming and reflexive metaprogramming features, and on domain-specific languages. REFERENCES [1] Bentley, J., Programming pearls: Little languages, Communications of the ACM, 29 (8), 711-721, 1986. [2] Carlson, L., Richardson, L., Ruby Cookbook, O’Reilly, 2006 [3] Freeze, J., Creating DSLs with Ruby, Artima Developer, http://www.artima.com/rubycs/articles/ruby_as_dsl.html, March 2006. [4] Fowler, M., Language workbenches: The killer-app for domain specific languages? http://www.martinfowler.com/articles/languageWorkbench.html, June 2005. [5] Fowler, M., Generating code for DSLs, http://www.martinfowler.com/articles/codeGenDsl.html, June 2005. [6] Mernik, M., Heering, J., Sloane, A. M., When and how to develop domain-specific languages, ACM Computing Surveys, 37 (4), 316-344, 2005. [7] Ruby on Rails Project, http://www.rubyonrails.org, accessed December 2, 2006.
  • 2. [8] Tate, B., Beyond Java, O’Reilly, 2005. [9] Tate, B., From Java to Ruby: Things Every Manager Should Know, Pragmatic Bookshelf, 2006. [10] Thomas, D., Fowler, C., Hunt, A., Programming Ruby: The Pragmatic Programmers' Guide, Second Edition, Pragmatic Bookshelf, 2005. [11] Thomas, D., Heinemeier Hansson, D., Agile Web Development with Rails, Second Edition, Pragmatic Bookshelf, 2006. [12] Wikipedia: The Free Encyclopedia, Metaprogramming, http://en.wikipedia.org/wiki/Metaprogramming, accessed December 2, 2006.