On Sun, Aug 22, 2010 at 7:34 AM, Dave Castellano <lists@ruby-forum.com> wrote:
> New to programming and hoping someone can help with this. I'm trying to
> format a hash in a model so I can access the individual values in a view
> def set_format_for_presentation # This method is in the model.
> answer_list = [
> [self.incorrect_ans_1, self.incorrect_anno_1,
> self.incorrect_ans_pict_1],
> [self.incorrect_ans_2, self.incorrect_anno_2,
> self.incorrect_ans_pict_2]
> .shuffle
While I don't know your whole use case, I'd suggest that this isn't very
Rubyish/OO.
Your "answer_list" implies there's such a thing as an "answer" -- so
why not make an Answer model with those attributes? Then you can
have a collection of answers as easily as
@answers = Answer.all # or some subset as desired...
And `self.incorrect_ans_pict_1`, `self.incorrect_ans_pict_2`, etc. is
just not a scalable pattern.
FWIW!
--
Hassan Schroeder ------------------------ hassan.schroeder@gmail.com
twitter: @hassan
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
No comments:
Post a Comment