Skip to content

Instantly share code, notes, and snippets.

@Prajjwal
Created May 28, 2016 14:01
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 Prajjwal/1f870ce9c6917a907f87e1f3e8583e5a to your computer and use it in GitHub Desktop.
Save Prajjwal/1f870ce9c6917a907f87e1f3e8583e5a to your computer and use it in GitHub Desktop.
require_relative 'library'
# This is the library:
#
# class Lord
# def self.printar(x)
# puts x.reverse
# end
# end
module StringExtensions
refine String do
def reverse
"Refined reverse()"
end
end
refine Fixnum do
def succ
self + 2
end
end
end
module StringStuff
using StringExtensions
puts "abcd".reverse # => Refined reverse()
Lord.printar("abcd") # => bcda
end
class CrazyString
using StringExtensions
def reverse
"nthoeunth".reverse
end
end
cs = CrazyString.new
puts cs.reverse # => Refined
Lord.printar(cs) # => Refined
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment