Skip to content

Instantly share code, notes, and snippets.

@jeremywrowe
Last active January 2, 2016 09:29
Show Gist options
  • Save jeremywrowe/8283427 to your computer and use it in GitHub Desktop.
Save jeremywrowe/8283427 to your computer and use it in GitHub Desktop.
Example of ruby 2.1 refinements and their glory. Use with caution -- They are kind of code stinkies.
module Refinement
refine String do
def reverse
self[0..1]
end
end
end
class Boom
using Refinement
def bar
"abc123".reverse
end
end
puts Boom.new.bar #=> "ab"
puts "abc123".reverse #=> "321cba"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment