Created
May 28, 2016 14:01
-
-
Save Prajjwal/1f870ce9c6917a907f87e1f3e8583e5a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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