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

  • Home
  • SEARCH
  • 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 6948435
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:49:21+00:00 2026-05-27T13:49:21+00:00

I have an attributes array as follows, attributes = [test, 2011, photo, 198.1 x

  • 0

I have an attributes array as follows,

attributes = ["test, 2011", "photo", "198.1 x 198.1 cm", "Photo: Manu PK Full Screen"]

When i do this,

artist = attributes[-1].gsub("Photo:")
p artist

i get the following output in terminal

#<Enumerator: "Photo: Manu PK Full Screen":gsub("Photo:")>

Wondering why am I getting an enumerator object as output? Thanks in advance.

EDIT:
Please note that instead of attributes[-1].gsub("Photo:", ""), I am doing attributes[-1].gsub("Photo:") So would like to know why enumerator object has returned here( I was expecting an error message) and what is going on.?

Ruby – 1.9.2

Rails – 3.0.7

  • 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-05-27T13:49:22+00:00Added an answer on May 27, 2026 at 1:49 pm

    An Enumerator object provides some methods common to enumerations — next, each, each_with_index, rewind, etc.

    You’re getting the Enumerator object here because gsub is extremely flexible:

    gsub(pattern, replacement) → new_str
    gsub(pattern, hash) → new_str
    gsub(pattern) {|match| block } → new_str
    gsub(pattern) → enumerator 
    

    In the first three cases, the substitution can take place immediately, and return a new string. But, if you don’t give a replacement string, a replacement hash, or a block for replacements, you get back the Enumerator object that lets you get to the matched pieces of the string to work with later:

    irb(main):022:0> s="one two three four one"
    => "one two three four one"
    irb(main):023:0> enum = s.gsub("one")
    => #<Enumerable::Enumerator:0x7f39a4754ab0>
    irb(main):024:0> enum.each_with_index {|e, i| puts "#{i}: #{e}"}
    0: one
    1: one
    => " two three four "
    irb(main):025:0> 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this array: [@attributes] => Array ( [url] => [navigation] => true [template]
I have an array of objects that have QTTime structs as attributes. The objects
I have a two dimensional JSON array where each element contains several attributes. The
I have the following XML array: [link]=> array(2) { [0]=> object(SimpleXMLElement)#311 (1) { [@attributes]=>
So I have an array with objects which each have several attributes including an
I have an an array which I can get the string name from. arr[i].getName();
Here's a problem I ran into recently. I have attributes strings of the form
I have 2 attributes that I use within the controllers of my MVC application.
I have quite a lot of music files but their title attributes have the
I have a component with a number of properties that have various attributes Normally

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.