This can be done by building blocks of Ruby code as strings, based on user input, and then embedding these blocks into the rest of the program.
To do this, we'll focus on four primary techniques:
A copy of the readme is posted below. Note that it can be something practical, or weird, or interesting, or just plain fun!
Assignment 5 Readme ------------------- A 400-level topics course should allow some room for creativity on the part of the student. As such, assignment 5 is left as a wide-open exercise for you to experiment with generating and applying code "on-the-fly" in Ruby. The objective is to come up with an interesting example of coding on the fly and an implementation for it that works. The code examples included in the repository give some ideas on how to get started, but you are welcome to use other techniques and approaches. Three example ruby files are included in the repo, illustrating three different techniques for generating and applying code "on the fly": modules containing user methods defined on the fly: onTheFly_modules.rb methods that can be passed blocks of code generated on the fly: (1) using Proc: onTheFly_proc.rb (2) using yield: onTheFly_yields.rb |