[prev in list] [next in list] [prev in thread] [next in thread]
List: ruby-talk
Subject: exiting of a block
From: Emmanuel Touzery <emmanuel.touzery () wanadoo ! fr>
Date: 2003-05-26 6:30:28
[Download RAW message or body]
Hello,
it's a newbie question...
i wanted to do something like:
result1 = [1, 2, 3].find { |e|
if e == 2
return true
else
return false
end
}
(with several if/else one in each other rather than one big condition, for
code readability)
but I realised that 'return' does not apply to a block, but only to a
function. it's a bit (actually very) un-intuitive for me, but anyway, is
there a nicer solution than doing my current:
item = [1, 2, 3].find { |e|
result = false
if e == 2
result = true
else
result = false
end
result
}
for reference, here is my real code. I'm searching the current TV program at
showTime from a DB of tv programs i fetched from the net. a program for sure
has a start time (time), but not necessarily an end time (if it's the last tv
program on the web page, i can't know).
# now find the current program for this
# channel.
programsForChannel.find { |program|
result = false
if program.time <= showTime
if program.endTime
# there is a endtime.
# are we now before this end?
if program.endTime > showTime
result = true
end
else
# program has no registered
# end.
result = true
end
end
result
}
any help appreciated!
emmanuel
--
"If there is any kind of God, it's not in you or in me,
but in the space between us"
-- Celine, "Before Sunrise"
(It's not about what you do, it's about what you give.)
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic