Steve L
4/28/2006 2:08:00 AM
Hello,
I have a class called Preferance that will contain method to retreive
and set various user preferances.
If my app has 2 user defined preferances then my class might look like
the following
class Preference
def self.pref1
end
def self.pref2
end
def self.pref1=
end
def self.pref2=
end
end
Inside of each of these class methods is some sql code to retieve/set values
in my database.
The code for pref1 and pref2 is extremely similiar.
I would like to automatically generate these methods. (Because I have 50
different user preferances.)
My imaginary code would something like this
class Preference
@list_of_preference = ['max','min','timeout']
list_of_preferance.each | method_name | do
define_class_method method_name
end
end
If the above code actually worked as I imagine it, I would be able to do the
following
Preference.max =10
Preference.min = 5
Preference.timeout = 13
Also, when I needed to add a another 10 user preferances, I would simply add
some values to the @list_of_preference array.
Is this possible?
Janak