Petty Annoyance of the day #1
Methods that return different object types given different input. I understand why this does what it does but when you forget the 2nd argument and an Enumerator arrives unexpectedly….
2.1.2 :068 > 'somestring'.gsub(':').class
=> Enumerator
2.1.2 :069 > 'somestring'.gsub(':','').class
=> String
Not sure why its Enumerator
2.1.2 :085 > 'string'.gsub(/(s)trin(g)/).each do |blah|
2.1.2 :086 > puts blah
2.1.2 :087?> end
string
2.1.2 :099 > 'string'.gsub('staobasf').map(&:object_id)
=> []
2.1.2 :100 > 'string'.gsub('staobasf').map
=> #<Enumerator: #<Enumerator: "string":gsub("staobasf")>:map>
I am pretty sure I don’t need to know but hey.