Getting a 'true' value out of a method?

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

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

here is my code :

def check_dispo(date, time, time_duration, week_duration)
i = 0
end_time = time + time_duration.strftime(’%H’).to_i3600 +
time_duration.strftime(’%M’).to_i
60
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_i3600 +
studio_booking.time_duration.strftime(’%M’).to_i
60
unless time >= studio_booking_end_time || end_time <=
studio_booking.time
return false
end
end
i += 1
date = date + 7
end
return true
end

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 Y.
http://notahat.com/

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs