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
An
Enumeratorobject provides some methods common to enumerations —next,each,each_with_index,rewind, etc.You’re getting the
Enumeratorobject here becausegsubis extremely flexible: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
Enumeratorobject that lets you get to the matched pieces of the string to work with later: