Hi all: Ruby newbie here. Been trying to get this code to work but am
having a tough time of it. Can anyone else please help me out?
I’ve read from a db into an array, and would like to go through the
array and remove elements which match a specific criteria. Here is the
code that I’m using:
load array
@array = Capture.find(:all)
iterate through array
for x in @array
x.reject!{|x| x.text =~ “something”}
end
Hi all: Ruby newbie here. Been trying to get this code to work but am
having a tough time of it. Can anyone else please help me out?
I’ve read from a db into an array, and would like to go through the
array and remove elements which match a specific criteria. Here is the
code that I’m using:
load array
@array = Capture.find(:all)
iterate through array
for x in @array
x.reject!{|x| x.text =~ “something”}
end
Sorry: forgot to mention that this breaks with an undefined method
reject!
Hi all: Ruby newbie here. Been trying to get this code to work but am
having a tough time of it. Can anyone else please help me out?
I’ve read from a db into an array, and would like to go through the
array and remove elements which match a specific criteria. Here is the
code that I’m using:
load array
@array = Capture.find(:all)
iterate through array
for x in @array
x.reject!{|x| x.text =~ “something”}
end
reject! does the iterating for you, so you can (must) leave out the for
loop.
The #reject! method is an iterator; so is the for loop (effectively).
So you’re iterating over the array, and then trying to iterate over
individual members of the array. Here’s what you want:
The #reject! method is an iterator; so is the for loop (effectively).
So you’re iterating over the array, and then trying to iterate over
individual members of the array. Here’s what you want:
The #reject! method is an iterator; so is the for loop (effectively).
So you’re iterating over the array, and then trying to iterate over
individual members of the array. Here’s what you want: