Juggling Chainsaws at Machu Picchu: Metaprogramming in Ruby
14-Dec-2018 2023
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 #Juggling #Chainsaws #Machu #Picchu: #Metaprogramming https://rubyonrails.ba/link/juggling-chainsaws-at-machu-picchu-metaprogramming-in-ruby