Undefined method `each'

Before I explain the issue I’m having I should preface it with some
important information. I’m a novice programmer at best and I’m new to
Ruby…

I’m trying to capture the authentication token from Nessus so I can use
it to run scans, reports, etc. I found the following code on the Nessus
site but I’m getting “undefined method `each’ for
#String:0x00000001458a10 (NoMethodError)” from a line of code near the
bottom (response.body.each do |line|). I’m using Ruby 1.9.1 running on
Linux (Ubuntu 10.04). Any insight you can provide would be much
appreciated!

Russ Forsythe wrote in post #958057:

Before I explain the issue I’m having I should preface it with some
important information. I’m a novice programmer at best and I’m new to
Ruby…

I’m trying to capture the authentication token from Nessus so I can use
it to run scans, reports, etc. I found the following code on the Nessus
site but I’m getting “undefined method `each’ for
#String:0x00000001458a10 (NoMethodError)” from a line of code near the
bottom (response.body.each do |line|). I’m using Ruby 1.9.1 running on
Linux (Ubuntu 10.04). Any insight you can provide would be much
appreciated!

ruby 1.8 had String#each, ruby 1.9 does not. Use String#each_line
instead.

(However, strangely, IO#each still exists)

Russ Forsythe wrote in post #958057:

Before I explain the issue I’m having I should preface it with some
important information. I’m a novice programmer at best and I’m new to
Ruby…

I’m trying to capture the authentication token from Nessus so I can use
it to run scans, reports, etc. I found the following code on the Nessus
site but I’m getting “undefined method `each’ for
#String:0x00000001458a10 (NoMethodError)” from a line of code near the
bottom (response.body.each do |line|). I’m using Ruby 1.9.1 running on
Linux (Ubuntu 10.04). Any insight you can provide would be much
appreciated!

Hi
It seems that the method “each” in String has been removed from
version
1.9.*,you can see the build-in method declaration in string.c:

rb_define_method(rb_cString, "each_line", rb_str_each_line, -1);
rb_define_method(rb_cString, "each_byte", rb_str_each_byte, 0);
rb_define_method(rb_cString, "each_char", rb_str_each_char, 0);
rb_define_method(rb_cString, "each_codepoint",

rb_str_each_codepoint, 0);

There is no “each”,use “each_line” or others instead.

Wow, I didn’t expect that to be the issue. I’ll give it a try with
“each_line”. Thanks so much for your help!

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