SlideShare a Scribd company logo
1 of 2
Download to read offline
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

Similar to RubyMetaprogramming

Evolution Of Object Oriented Technology
Evolution Of Object Oriented TechnologyEvolution Of Object Oriented Technology
Evolution Of Object Oriented Technology
Sharon Roberts
 
Scales02WhatProgrammingLanguagesShouldWeTeachOurUndergraduates
Scales02WhatProgrammingLanguagesShouldWeTeachOurUndergraduatesScales02WhatProgrammingLanguagesShouldWeTeachOurUndergraduates
Scales02WhatProgrammingLanguagesShouldWeTeachOurUndergraduates
Hans Ecke
 
Comparative Analysis of Visual Basic VS Java programming language.docx
Comparative Analysis of Visual Basic VS Java programming language.docxComparative Analysis of Visual Basic VS Java programming language.docx
Comparative Analysis of Visual Basic VS Java programming language.docx
RichwellIanAfrica
 
A Survey of Object Oriented Programming LanguagesMaya Hris.docx
A Survey of Object Oriented Programming LanguagesMaya Hris.docxA Survey of Object Oriented Programming LanguagesMaya Hris.docx
A Survey of Object Oriented Programming LanguagesMaya Hris.docx
daniahendric
 
1 preliminaries
1 preliminaries1 preliminaries
1 preliminaries
jigeno
 

Similar to RubyMetaprogramming (20)

Towards Language-Oriented Modeling (HDR Defense)
Towards Language-Oriented Modeling (HDR Defense)Towards Language-Oriented Modeling (HDR Defense)
Towards Language-Oriented Modeling (HDR Defense)
 
Unit ii oo design 9
Unit ii oo design 9Unit ii oo design 9
Unit ii oo design 9
 
A Survey on Various Web Technologies
A Survey on Various Web TechnologiesA Survey on Various Web Technologies
A Survey on Various Web Technologies
 
Evolution Of Object Oriented Technology
Evolution Of Object Oriented TechnologyEvolution Of Object Oriented Technology
Evolution Of Object Oriented Technology
 
Programming languages
Programming languagesProgramming languages
Programming languages
 
The different kind of programming language
The  different kind of programming languageThe  different kind of programming language
The different kind of programming language
 
Java-centered Translator-based Multi-paradigm Software Development Environment
Java-centered Translator-based Multi-paradigm Software Development EnvironmentJava-centered Translator-based Multi-paradigm Software Development Environment
Java-centered Translator-based Multi-paradigm Software Development Environment
 
8505548.ppt
8505548.ppt8505548.ppt
8505548.ppt
 
Programming-Languages.pptx
Programming-Languages.pptxProgramming-Languages.pptx
Programming-Languages.pptx
 
Scales02WhatProgrammingLanguagesShouldWeTeachOurUndergraduates
Scales02WhatProgrammingLanguagesShouldWeTeachOurUndergraduatesScales02WhatProgrammingLanguagesShouldWeTeachOurUndergraduates
Scales02WhatProgrammingLanguagesShouldWeTeachOurUndergraduates
 
20210417-cppRelevancy-DataStructures.pptx
20210417-cppRelevancy-DataStructures.pptx20210417-cppRelevancy-DataStructures.pptx
20210417-cppRelevancy-DataStructures.pptx
 
Comparative Analysis of Visual Basic VS Java programming language.docx
Comparative Analysis of Visual Basic VS Java programming language.docxComparative Analysis of Visual Basic VS Java programming language.docx
Comparative Analysis of Visual Basic VS Java programming language.docx
 
Programming language
Programming languageProgramming language
Programming language
 
Programming Language
Programming LanguageProgramming Language
Programming Language
 
English de lenguaje de programacion
English de lenguaje de programacionEnglish de lenguaje de programacion
English de lenguaje de programacion
 
A Survey of Object Oriented Programming LanguagesMaya Hris.docx
A Survey of Object Oriented Programming LanguagesMaya Hris.docxA Survey of Object Oriented Programming LanguagesMaya Hris.docx
A Survey of Object Oriented Programming LanguagesMaya Hris.docx
 
OOP and Its Calculated Measures in Programming Interactivity
OOP and Its Calculated Measures in Programming InteractivityOOP and Its Calculated Measures in Programming Interactivity
OOP and Its Calculated Measures in Programming Interactivity
 
1 preliminaries
1 preliminaries1 preliminaries
1 preliminaries
 
Software architecture styles families_research_gssi_nov2013
Software architecture styles families_research_gssi_nov2013Software architecture styles families_research_gssi_nov2013
Software architecture styles families_research_gssi_nov2013
 
Impacts of Object Oriented Programming on Web Application Development
Impacts of Object Oriented Programming on Web Application DevelopmentImpacts of Object Oriented Programming on Web Application Development
Impacts of Object Oriented Programming on Web Application Development
 

More from tutorialsruby

<img src="../i/r_14.png" />
<img src="../i/r_14.png" /><img src="../i/r_14.png" />
<img src="../i/r_14.png" />
tutorialsruby
 
TopStyle Help & <b>Tutorial</b>
TopStyle Help & <b>Tutorial</b>TopStyle Help & <b>Tutorial</b>
TopStyle Help & <b>Tutorial</b>
tutorialsruby
 
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting <b>...</b>
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting <b>...</b>The Art Institute of Atlanta IMD 210 Fundamentals of Scripting <b>...</b>
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting <b>...</b>
tutorialsruby
 
<img src="../i/r_14.png" />
<img src="../i/r_14.png" /><img src="../i/r_14.png" />
<img src="../i/r_14.png" />
tutorialsruby
 
<img src="../i/r_14.png" />
<img src="../i/r_14.png" /><img src="../i/r_14.png" />
<img src="../i/r_14.png" />
tutorialsruby
 
Standardization and Knowledge Transfer – INS0
Standardization and Knowledge Transfer – INS0Standardization and Knowledge Transfer – INS0
Standardization and Knowledge Transfer – INS0
tutorialsruby
 
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa0602690047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
tutorialsruby
 
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa0602690047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
tutorialsruby
 
BloggingWithStyle_2008
BloggingWithStyle_2008BloggingWithStyle_2008
BloggingWithStyle_2008
tutorialsruby
 
BloggingWithStyle_2008
BloggingWithStyle_2008BloggingWithStyle_2008
BloggingWithStyle_2008
tutorialsruby
 
cascadingstylesheets
cascadingstylesheetscascadingstylesheets
cascadingstylesheets
tutorialsruby
 
cascadingstylesheets
cascadingstylesheetscascadingstylesheets
cascadingstylesheets
tutorialsruby
 

More from tutorialsruby (20)

<img src="../i/r_14.png" />
<img src="../i/r_14.png" /><img src="../i/r_14.png" />
<img src="../i/r_14.png" />
 
TopStyle Help & <b>Tutorial</b>
TopStyle Help & <b>Tutorial</b>TopStyle Help & <b>Tutorial</b>
TopStyle Help & <b>Tutorial</b>
 
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting <b>...</b>
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting <b>...</b>The Art Institute of Atlanta IMD 210 Fundamentals of Scripting <b>...</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" /><img src="../i/r_14.png" />
<img src="../i/r_14.png" />
 
<img src="../i/r_14.png" />
<img src="../i/r_14.png" /><img src="../i/r_14.png" />
<img src="../i/r_14.png" />
 
Standardization and Knowledge Transfer – INS0
Standardization and Knowledge Transfer – INS0Standardization and Knowledge Transfer – INS0
Standardization and Knowledge Transfer – INS0
 
xhtml_basics
xhtml_basicsxhtml_basics
xhtml_basics
 
xhtml_basics
xhtml_basicsxhtml_basics
xhtml_basics
 
xhtml-documentation
xhtml-documentationxhtml-documentation
xhtml-documentation
 
xhtml-documentation
xhtml-documentationxhtml-documentation
xhtml-documentation
 
CSS
CSSCSS
CSS
 
CSS
CSSCSS
CSS
 
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa0602690047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
 
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa0602690047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
 
HowTo_CSS
HowTo_CSSHowTo_CSS
HowTo_CSS
 
HowTo_CSS
HowTo_CSSHowTo_CSS
HowTo_CSS
 
BloggingWithStyle_2008
BloggingWithStyle_2008BloggingWithStyle_2008
BloggingWithStyle_2008
 
BloggingWithStyle_2008
BloggingWithStyle_2008BloggingWithStyle_2008
BloggingWithStyle_2008
 
cascadingstylesheets
cascadingstylesheetscascadingstylesheets
cascadingstylesheets
 
cascadingstylesheets
cascadingstylesheetscascadingstylesheets
cascadingstylesheets
 

Recently uploaded

Structuring Teams and Portfolios for Success
Structuring Teams and Portfolios for SuccessStructuring Teams and Portfolios for Success
Structuring Teams and Portfolios for Success
UXDXConf
 
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
panagenda
 

Recently uploaded (20)

What's New in Teams Calling, Meetings and Devices April 2024
What's New in Teams Calling, Meetings and Devices April 2024What's New in Teams Calling, Meetings and Devices April 2024
What's New in Teams Calling, Meetings and Devices April 2024
 
ECS 2024 Teams Premium - Pretty Secure
ECS 2024   Teams Premium - Pretty SecureECS 2024   Teams Premium - Pretty Secure
ECS 2024 Teams Premium - Pretty Secure
 
WebAssembly is Key to Better LLM Performance
WebAssembly is Key to Better LLM PerformanceWebAssembly is Key to Better LLM Performance
WebAssembly is Key to Better LLM Performance
 
1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT
1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT
1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT
 
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdfIntroduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
 
How we scaled to 80K users by doing nothing!.pdf
How we scaled to 80K users by doing nothing!.pdfHow we scaled to 80K users by doing nothing!.pdf
How we scaled to 80K users by doing nothing!.pdf
 
Google I/O Extended 2024 Warsaw
Google I/O Extended 2024 WarsawGoogle I/O Extended 2024 Warsaw
Google I/O Extended 2024 Warsaw
 
Structuring Teams and Portfolios for Success
Structuring Teams and Portfolios for SuccessStructuring Teams and Portfolios for Success
Structuring Teams and Portfolios for Success
 
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdfSimplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
 
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
 
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdfThe Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
 
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdf
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdfHow Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdf
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdf
 
Your enemies use GenAI too - staying ahead of fraud with Neo4j
Your enemies use GenAI too - staying ahead of fraud with Neo4jYour enemies use GenAI too - staying ahead of fraud with Neo4j
Your enemies use GenAI too - staying ahead of fraud with Neo4j
 
Continuing Bonds Through AI: A Hermeneutic Reflection on Thanabots
Continuing Bonds Through AI: A Hermeneutic Reflection on ThanabotsContinuing Bonds Through AI: A Hermeneutic Reflection on Thanabots
Continuing Bonds Through AI: A Hermeneutic Reflection on Thanabots
 
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
 
Working together SRE & Platform Engineering
Working together SRE & Platform EngineeringWorking together SRE & Platform Engineering
Working together SRE & Platform Engineering
 
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
 
Portal Kombat : extension du réseau de propagande russe
Portal Kombat : extension du réseau de propagande russePortal Kombat : extension du réseau de propagande russe
Portal Kombat : extension du réseau de propagande russe
 
AI mind or machine power point presentation
AI mind or machine power point presentationAI mind or machine power point presentation
AI mind or machine power point presentation
 
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
 

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.