Forum: Ruby on Rails Getting a 'true' value out of a method ?

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
13682a31fd31f1dba8ae80e492d59768?d=identicon&s=25 Pat (Guest)
on 2007-05-08 22:04
(Received via mailing list)
Hi, I'm having trouble with one of my apps.

I'm trying to make a studio booking software.

Before creating a booking, I want to check if the studio is available.

I have a method checking for the availability of the studio which
returns false if the studio is already booked.

The problem is that the method returns 'nil' if the checking process

I tried a bunch of methods but none of them worked :(

here is my code :

  def check_dispo(date, time, time_duration, week_duration)
    i = 0
    end_time = time + time_duration.strftime('%H').to_i*3600 +
    while i < week_duration
      studio_bookings = StudioBooking.find(:all, :conditions =>
["start_date = ?", date])
        for studio_booking in studio_bookings
          studio_booking_end_time = studio_booking.time +
studio_booking.time_duration.strftime('%H').to_i*3600 +
          unless time >= studio_booking_end_time || end_time <=
            return false
      i += 1
      date = date + 7
    return true
C9c7a65848f13e2b1a226bbe43bc3672?d=identicon&s=25 Pete Yandell (pete)
on 2007-05-09 01:44
(Received via mailing list)
On 09/05/2007, at 5:46 AM, Pat wrote:

> The problem is that the method returns 'nil' if the checking process
> succeeds.

Well, your method has two return statements in it, neither of which
return nil, so this sounds impossible to me. Can you give an example
set of arguments for which your method will return nil?

Pete Yandell
This topic is locked and can not be replied to.