I want to make DSL construction for my class something like
class Car
brand :mercedes
end
What code I need to write?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
brandshould be a method. It has to be defined somewhere. You have options: the very same class, parent class or mixed module. I like modules.While this answers your concrete question, I strongly recommend getting this book: Metaprogramming Ruby. Seems that you’ll find many answers there.