August 14, 2015 Log No. 334

Off to See the Wizard

Or rather I guess I AM the Wizard, because today was metaprogramming. Now I know what makes ActiveRecord so magical. Ruby makes self-referential code (relatively) easy, so we were able to dive in and make our own ActiveRecord Lite today. It was a little tough going at first, not just because meta stuff can seem kinda abstract–after a week of mostly SQL, it took some time to remember how Ruby worked…But it came back soon, haha. Saw my old friend instance_variable_get again, along with instance_variable_set, define_method, and send.

Also we touched upon scope again, as that is pretty important when you are literally writing code that writes code: what would be the scope of your new method/variables, and is it what you’re looking for? And so we briefly talked about class variables, which led to an interesting thought that I’m surprised I never realized before: class variables are just instance variables in a larger “Class” scope. Whaaaa?! Too deep.


Leave a Reply

Your email address will not be published. Required fields are marked *

*