“...I've been working since 2008 with Ruby / Ruby on Rails, love a bit of Elixir / Phoenix and learning Rust. I also poke through other people's code and make PRs for OpenSource Ruby projects that sometimes make it. Currently working for InPay...”

Rob Lacey (contact@robl.me)
Senior Software Engineer, Brighton, UK

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.