Posts tagged with: "metaprogramming"

Implementing DRY Magic Methods in Ruby

By Michael Bleigh November 16, 2011 in ruby, metaprogramming, how to

Small

As a new developer to Ruby you might wonder how certain methods seem to be magically available without being strictly defined. Rails's dynamic finders (e.g. find_by_name) are one example of this kind of magic. It's very simple to implement magic such as this in Ruby, but it's also easy to implement things in a way that doesn't entirely mesh with standard Ruby object expectations.

Twas Brillig, and the Slithy Code...

By Kevin Gisi May 3, 2011 in tips, development, metaprogramming, code, legacy code

Small

No matter what level of developer you are, at some point you will have the underrated joy of inheriting a legacy software project. And since we're fortunate enough to work in such a fast-paced community and ecosystem, "legacy" really encapsulates any piece of software more than a week or two old. Often though, we don't have time to appreciate how our ancestors used to write Ruby back in the days of Rails 2.3, or even (gasp) 2.1 — we need to get right to work. It's at this point that the nefarious Jabberwocky method can rear its ugly head.

ActiveRecord::Base.create_or_update on Steroids

By Michael Bleigh February 19, 2008 in rails, ActiveRecord, db-populate, metaprogramming, seed data