Ruby on Rails Tuesday, August 31, 2010

On 31 August 2010 19:48, lucas franceschi <lukas1596@gmail.com> wrote:
> Word.times = 3
> Word.name = a
> Word.complete = aaa
> got it?
> i wont store that data, but generate it based on the data that is stored.
> any idea????
> did any of you guys see this situation before???

once or twice...

what you're after is a "method"...

(you may run into trouble if you try to call your column 'times', I'll
use 'times_repeated' in this example)

# word.rb
def complete
self.name * self.times_repeated if self.name
end

I recommend going through some Ruby tutorials - the "Ruby for Rails"
book has a good coverage of getting started through to intermediate
use.

--
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