undefined method `each'

Discussion in 'Ruby' started by Russ F., Oct 29, 2010.

  1. Russ F.

    Russ F. Guest

    Before I explain the issue I=E2=80=99m having I should preface it with so=
    me
    important information. I=E2=80=99m a novice programmer at best and I=E2=80=
    =99m new to
    Ruby=E2=80=A6

    I=E2=80=99m trying to capture the authentication token from Nessus so I c=
    an use
    it to run scans, reports, etc. I found the following code on the Nessus
    site but I=E2=80=99m getting =E2=80=9Cundefined method `each' for
    #<String:0x00000001458a10> (NoMethodError)=E2=80=9D from a line of code n=
    ear the
    bottom (response.body.each do |line|). I=E2=80=99m using Ruby 1.9.1 runn=
    ing on
    Linux (Ubuntu 10.04). Any insight you can provide would be much
    appreciated!

    Attachments:
    http://www.ruby-forum.com/attachment/5266/Nessus_logon.txt


    -- =

    Posted via http://www.ruby-forum.com/.=
    Russ F., Oct 29, 2010
    #1
    1. Advertising

  2. Russ Forsythe wrote in post #958057:
    > Before I explain the issue I=E2=80=99m having I should preface it with =

    some
    > important information. I=E2=80=99m a novice programmer at best and I=E2=

    =80=99m new to
    > Ruby=E2=80=A6
    >
    > I=E2=80=99m 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 Nessu=

    s
    > site but I=E2=80=99m getting =E2=80=9Cundefined method `each' for
    > #<String:0x00000001458a10> (NoMethodError)=E2=80=9D from a line of code=

    near the
    > bottom (response.body.each do |line|). I=E2=80=99m using Ruby 1.9.1 ru=

    nning 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)

    -- =

    Posted via http://www.ruby-forum.com/.=
    Brian Candler, Oct 29, 2010
    #2
    1. Advertising

  3. Russ F.

    Adrian Tepes Guest

    Russ Forsythe wrote in post #958057:
    > Before I explain the issue I=E2=80=99m having I should preface it with =

    some
    > important information. I=E2=80=99m a novice programmer at best and I=E2=

    =80=99m new to
    > Ruby=E2=80=A6
    >
    > I=E2=80=99m 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 Nessu=

    s
    > site but I=E2=80=99m getting =E2=80=9Cundefined method `each' for
    > #<String:0x00000001458a10> (NoMethodError)=E2=80=9D from a line of code=

    near the
    > bottom (response.body.each do |line|). I=E2=80=99m using Ruby 1.9.1 ru=

    nning on
    > Linux (Ubuntu 10.04). Any insight you can provide would be much
    > appreciated!


    Hi
    It seem 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.

    -- =

    Posted via http://www.ruby-forum.com/.=
    Adrian Tepes, Oct 29, 2010
    #3
  4. 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!

    --
    Posted via http://www.ruby-forum.com/.
    Russ Forsythe, Nov 1, 2010
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John Blair
    Replies:
    1
    Views:
    396
    Eliyahu Goldin
    Aug 3, 2005
  2. Tjerk Wolterink

    xsl:for-each for each 3 elements problem

    Tjerk Wolterink, Nov 3, 2004, in forum: XML
    Replies:
    3
    Views:
    416
    Tjerk Wolterink
    Nov 3, 2004
  3. Joshua Ball

    undefined method 'each'

    Joshua Ball, Nov 17, 2008, in forum: Ruby
    Replies:
    2
    Views:
    188
    James Herdman
    Nov 17, 2008
  4. Sonja Elen Kisa
    Replies:
    1
    Views:
    148
    Eric Christopherson
    Jul 30, 2010
  5. Su Zhang
    Replies:
    3
    Views:
    201
    Su Zhang
    Apr 18, 2011
Loading...

Share This Page