# Getting a 'true' value out of a method?

**URL:** <https://www.ruby-forum.com/t/getting-a-true-value-out-of-a-method/103649>\
**Category:** Rails\
**Created:** [May 8, 2007, 10:04pm UTC](https://www.ruby-forum.com/t/getting-a-true-value-out-of-a-method/103649 "2007-05-08T22:04:46Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![pat](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/8491ac/32.png) [@pat](https://www.ruby-forum.com/u/pat)\
**Post date:** [May 8, 2007, 10:04pm UTC](https://www.ruby-forum.com/t/getting-a-true-value-out-of-a-method/103649/1 "2007-05-08T22:04:46Z")

</div>

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 ☹

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 +  
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\_i_3600 +  
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

---

<div class="post-metadata">

**Author:** ![pat](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/8491ac/32.png) [@pat](https://www.ruby-forum.com/u/pat)\
**Post date:** [May 9, 2007, 1:44am UTC](https://www.ruby-forum.com/t/getting-a-true-value-out-of-a-method/103649/2 "2007-05-09T01:44:14Z")

</div>

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.

> **[Pete Yandell — Principal Engineer / Architect](https://notahat.com/)**
>
> Pete Yandell is an experienced Principal Software Engineer and Architect based in Melbourne, Australia.
