What are the performance issues associated with generating 100’s of dynamic methods in Ruby?
I’ve been interested in using the Ruby Preferences Gem and noticed that it generates a bunch of helper methods for each preference you set.
For instance:
class User < ActiveRecord::Base
preference :hot_salsa
end
…generates something like:
user.prefers_hot_salsa? # => false
user.prefers_hot_salsa # => false
If there are 100’s of preferences like this, how does this impact the application? I assume it’s not really a big deal but I’m just wondering, theoretically.
Almost every Ruby program does this sort of thing like crazy — this is what the standard
attr_family of methods do, which are used with impunity in pretty much every Ruby program ever. Many programs also do this in other places — it’s incredibly common withmethod_missinghacks, for instance. I’ve never timed to see exactly how it performs, but it’s common enough that if it were a significant problem, it should have been noticed by now.