Skip to content

Instantly share code, notes, and snippets.

@AJFaraday
Created August 18, 2014 13:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AJFaraday/b2b4c3901542ef9bc579 to your computer and use it in GitHub Desktop.
Save AJFaraday/b2b4c3901542ef9bc579 to your computer and use it in GitHub Desktop.
# gsub! doesn't return anything when no changes are made
irb(main):006:0> 'abc'.gsub('c','d')
=> "abd"
irb(main):007:0> 'abc'.gsub!('c','d')
=> "abd"
irb(main):008:0> 'abc'.gsub!('d','c')
=> nil
# It's usual usage pattern (working on an existing object) still works
irb(main):002:0> a = 'abc'
=> "abc"
irb(main):003:0> a.gsub! 'd',''
=> nil
irb(main):004:0> a
=> "abc"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment