Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.lang.ruby
Array.include? issue
-j b-
11/6/2008 6:33:00 PM
I have the following method defined within a class.
def move
@heading ||= '>'
@history << [@x,@y,@heading]
case @heading
when '>'
@y += 1
when '<'
@y -= 1
when '^'
@x -= 1
else
@x += 1
end
error_out("Infinite Loop") if @history.include?([@x,@y,@heading])
end
which works as expected on my linux machine. However, when I try the
same code on OS X the
error_out("Infinite Loop") if @history.include?([@x,@y,@heading])
fails to execute correctly. In other words, even if [@x,@y,@heading]
exists in @history the error_out is never executed. I have verified that
it does exist by printing the contents of the @history array before the
check.
This is a single threaded application and in no other place is @history
modified.
I first ran on OS X with ruby version 1.8.2 and then installed 1.8.7
with the same results. I am running version 1.8.7 on my linux machine.
Is there an obvious thing that I am missing here?
--
Posted via
http://www.ruby-...
.
2 Answers
Brian Candler
11/6/2008 9:11:00 PM
0
-j b- wrote:
> However, when I try the
> same code on OS X the
>
> error_out("Infinite Loop") if @history.include?([@x,@y,@heading])
>
> fails to execute correctly. In other words, even if [@x,@y,@heading]
> exists in @history the error_out is never executed. I have verified that
> it does exist by printing the contents of the @history array before the
> check.
How did you print it? If it were me I'd add
STDERR.puts @history.inspect
STDERR.puts [@x, @y, @heading]
just before the error_out line. What does this show?
Could it be that error_out() really is being called, but is not behaving
the way you expect? Try changing to
raise "Infinite loop" if @history.include?([@x,@y,@heading])
--
Posted via
http://www.ruby-...
.
Brian Candler
11/7/2008 8:53:00 AM
0
Brian Candler wrote:
> STDERR.puts @history.inspect
> STDERR.puts [@x, @y, @heading]
Oops, add .inspect at the end of the second line.
--
Posted via
http://www.ruby-...
.
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
Array.include? issue
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password