NoMethodError: undefined method `each' for true:TrueClass

Trying to use a method upto and place result into an array.

the below code loops through and run the curl command 6 times and place
results in “result” but its not an array.

1.upto(6) do |num|

puts num

result = system( “curl -Is -k --proxy http://one.proxy.com:8080
https://server#{num}-pod.com:8443” )
p result.inspect
end

I assume since the stdout is in the “result” then I could read through
it.

$c = 0
$bad = “”
1.upto(6) do |num|
puts num
result = system( “curl -Is -k --proxy http://one.proxy.com:8080
https://server#{num}-pod.com:8443” )

puts result

result.each do |line|
if line.include? “200”
$c += 1
puts $c
elsif line.to_s.include?(“https://master-server.com”)
$c += 1
puts $c
else
$bad += “#{line}\n”
puts $bad
end
end
end

I get the following error and any not sure what I am doing wrong? Or
maybe I am going about it all wrong.

NoMethodError: undefined method each' for true:TrueClass from (irb):32:in block in irb_binding’
from (irb):28:in upto' from (irb):28 from /usr/local/rvm/rubies/ruby-1.9.3-p551/bin/irb:12:in

You are invoking Kernel::sysem

result = system(....)

which, according to
Module: Kernel (Ruby 2.1.1), stores into
your variable ‘result’ either true, false or nil. In your case, the
system call succeeds, and ‘result’ contains true.

Next, you are doing

result.each .....

Since ‘result’ is true, and true is a value of class TrueClass, Ruby
searches an ‘each’ method in TrueClass, but doesn’t find one. Hence the
error.

In your case, you should process the output of a shell command. You can
do this by

result=%x(curl -Is -k --proxy http://one.proxy.com:8080

https://server#{num}-pod.com:8443)

Different to your original solution, everythin printed to stdout (by the
curl command) would NOT visible on the scrren, but stored into ‘result’.