On Tue, Sep 29, 2009 at 9:42 AM, Jake Brightmatter
b = false unless DataBase[:house][:id => i]
i += 1
The following might actually be a little easier to understand - typos
not guaranteed to exist or not exist
def find_unused_house_id(start_point = 0)
while (DataBase[:house][:id => start_point])
start_point += 1
This simply takes a starting point and will continue to loop through
you get a nil back from the database and then returns the id that got
nil back. I added the ability to pass in a starting point if you wanted
search from something other then 0 but if you just called the function
without a value then it would start at 0 by default.
It’s slightly different then you posted but I think if you are having
with syntax you should keep things nice and simple and this does that by
merely returning the id and you can do as you please with the value once
you’ve got it.
The while line could read “while (DataBase[:house][:id => start_point]
nil)” but the != is not necessary in this case.
Also, the reason for the start_point line at the bottom is that ruby
“return” the last value from the function and therefore just dropping
variable you want in as the last line works. You could use “return
start_point” if you wanted but the standard is just to loose the return.
Hope this helps some.