Iterate Array

Hi
I have created an array like
def checkdata(data)
@passed_effort= data.split(’:’).collect! {|n| n}
hours = @passed_effort[0]
minutes = @passed_effort[1]
@error_checked_value=Array.new
if hours =~ /\D/ || minutes =~ /\D/
@error_checked_value << ‘nonnumeric’
end
if minutes.to_i > 59
@error_checked_value << ‘notinrange’
end
return @error_checked_value
end

Now how can I iterate through this array
@error_checked_value.each do |val|
puts val
end

Is this correct?Or any other method?

Sijo

Using each is the most common way to iterate an array. Is there
something more than puts-ing each value that you want to do that
caused you to ask your question?

Regards,
Craig

Hi
I have a doubt regrding .collect That is why I asked tht.Is there any
such a method?

Sijo

2008/5/16 Sijo Kg [email protected]:

I have a doubt regrding .collect That is why I asked tht.Is there any
such a method?

Yes, there is. But your usage of collect does not make any sense:

xxx.collect! {|n| n}

Using #collect or #map with this block is basically a noop because
elements will be replaced by themselves.

Kind regards

robert

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs