Ruby on Rails Tuesday, June 28, 2011

On Jun 29, 12:04 am, John Merlino <stoici...@aol.com> wrote:
> actually you are right. my intention was to get the object with the
> smallest sequence number, not return the sequence number itself. The
> ruby documentation says this: "Returns the object in enum with the
> minimum value. " for min. Hence, I thought it would return the object.
>
>
It depends what you are iterating over - because you first called
map(&:sequence) the enumerable in question was the array of sequence
numbers. If you want to get back the object with the smallest sequence
value you should drop the call to map and either use the block form of
min or min_by

Fred
>
> > I suspect the error is actually being raised on the next line where
> > you do
>
> > available_book.sequence > 100
>
> > since you've set available_book
> > to available_books.flatten.map(&:sequence).min, ie available_book is
> > the smallest sequence number
>
> > Fred
>
> > > thanks for response

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