Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8655447
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T15:01:44+00:00 2026-06-12T15:01:44+00:00

I wrote some code: output = File.open(text_file).collect.reverse.join(<BR>) It seems to work okay on 1.8.7

  • 0

I wrote some code:

output = File.open(text_file).collect.reverse.join("<BR>")

It seems to work okay on 1.8.7 but throws the error

NoMethodError - undefined method 'reverse' for #<Enumerator: #<File:C:\EduTester\cron\rufus.log>:collect>:

on 1.9.1 (ruby 1.9.3p194 (2012-04-20) [i386-mingw32])

Does somebody know why this happens and how to fix this? (Why is of most interest to me.)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T15:01:46+00:00Added an answer on June 12, 2026 at 3:01 pm

    First how to fix it – you should be doing this:

    output = File.open(text_file).to_a.reverse.join("<BR>") 
    

    This will work on either version of Ruby. Basically you need to turn the file into an array of lines (with .to_a) before reversing them and adding line breaks.

    In terms of the why (this gets a little technical): File mixes in the Enumerable module, which gives it methods like collect. Now in Ruby 1.87, if you called Enumberable.collect without a block it would return an Array. But in 1.9, it returns an Enumerator – which doesn’t respond to the reverse method.

    Here are the 2 versions of the method in question:

    http://ruby-doc.org/core-1.8.7/Enumerable.html#method-i-collect
    http://ruby-doc.org/core-1.9.3/Enumerable.html#method-i-collect

    So basically before 1.9 .collect was a (hacky) equivalent to .to_a. But always use .to_a to turn something into an array.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wrote some code which monitors the output of Stopwatch using a tight loop.
I wrote some code to read a file in my Java Servlet class. (I'm
I wrote some code for the ising model in python (2d). Everything looks seems
For some reason I can't get open() to open a file. Here's my code.
I wrote some code in VHDL that is expected to look at a rotory
I wrote some code that activity starts a service to get some text from
I wrote some code (Java and LDAP) to create a user in the Active
I wrote some code today and It was changed by another developer who said
I have wrote some code to find out of 3 variables witch is the
I just wrote some code to test the behavior of std::equal, and came away

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.