Skip to content

Instantly share code, notes, and snippets.

@jc00ke
Last active August 29, 2015 14:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jc00ke/6ca48a30105e163344c2 to your computer and use it in GitHub Desktop.
Save jc00ke/6ca48a30105e163344c2 to your computer and use it in GitHub Desktop.
# 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
@chrishough
Copy link

Finally able to catch up on this today, I see your point. Well done. #bookmarked

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment