-
-
Save mocoso/4568915 to your computer and use it in GitHub Desktop.
This file contains 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
# Please rewrite the MyString definition, without using ruby keywords | |
# http://www.ruby-doc.org/docs/keywords/1.9/ | |
MyString = Class.new(String) { | |
define_singleton_method(:alphabet) { | |
'abc' | |
} | |
define_method(:exclaim) { |*args| | |
count = args.first || 1 | |
"#{self}#{exclamation_mark count}" | |
} | |
define_method(:!) { |*args| | |
exclaim *args | |
} | |
define_method(:exclamation_mark) { |count| | |
'!' * count | |
} | |
self.send :private, :exclamation_mark | |
} | |
j = MyString.new('james') | |
j.exclaim # "james!" | |
j.exclaim(4) # "james!!!!" | |
j.! # "james!" | |
MyString.alphabet # "abc" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment