Reflexive metaprogramming in Ruby: tutorial presentation

  • Authors:
  • H. Conrad Cunningham

  • Affiliations:
  • University of Mississippi, University, MS

  • Venue:
  • Journal of Computing Sciences in Colleges
  • Year:
  • 2007

Quantified Score

Hi-index 0.00

Visualization

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.