dear Rubyist
saya ada instance method di Active Record kira2 spt ini
def one=(one)
write_attribute(:one,"hello #{one}")
end
def two=(two)
write_attribute(:two,"hello #{two}")
end
def three=(three)
write_attribute(:three,"hello #{three}")
end
dst
saya pengen men DRY-ing method2 tsb dengan menggunakan define_method, dgn
syntax seperti ini
[:one,:two,:three].each do |field|
define_method "#{field}=(#{field})" do
write_attribute(field,"hello #{field}")
end
end
tapi koq itu nggak jalan yaa ?, kira2 apa yg salah ?
--
blog : http://adityakircon.blogsome.com
ym : kirconboy
skype : adit_skype
Be Nice. Treat others with the same respect you'd want them to treat you.
We're all here to learn together. Be tolerant of others who may not know
everything you know. BRING YOUR SENSE OF HUMOR (stackoverflow.com)
[Non-text portions of this message have been removed]