Juggling Chainsaws at Machu Picchu: Metaprogramming in Ruby

Metaprogramming means writing code that writes code itself. In Ruby, this means objects, classes, and methods can be created and modified during runtime.I’m going to illustrate some of Ruby’s metaprogramming features using the example of a program which creates methods on an existing object as and when they are required.Imagine we have been tasked to write a program to keep track of who was the first person to do something silly (eg juggling chainsaws) in an inappropriate location (eg Machu Picchu). Specifically, a user should be able to ask a particular location if they were the first person to perform a particular activity there. If so, they’ll get a message of congratulations. If not, they’ll be told which user was the first person to perform that activity in that place.
Juggling Chainsaws at Machu Picchu: Metaprogramming in Ruby #ruby #rubydeveloper #rubyonrails https://rubyonrails.ba/single/juggling-chainsaws-at-machu-picchu-metaprogramming-in-ruby

Nezir Zahirovic

Contractor Ruby On Rails (8+ years) / MCPD .Net / C# / Asp.Net / CSS / SQL / (11 years)

related articles