Last active
August 29, 2015 14:08
-
-
Save jc00ke/6ca48a30105e163344c2 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
# do | |
class CString | |
def initialize(string) | |
@string = string.to_s | |
end | |
def to_s | |
"comp:to_s - #{@string}" | |
end | |
end | |
# don't | |
class IString < String | |
def to_s | |
"int:to_s - #{self}" | |
end | |
end | |
c = CString.new("composed") | |
i = IString.new("inherited") | |
c.to_s | |
# => comp:to_s - composed | |
i.to_s | |
# => int:to_s - inherited | |
puts c | |
comp:to_s - composed | |
# => nil | |
puts i | |
int:to_s - inherited | |
# => nil |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Finally able to catch up on this today, I see your point. Well done. #bookmarked