def def_fizzBuzz(sel, n)
Integer.class_eval{
define_method(sel){
(m = self) % n == 0 ?
sel.to_s.capitalize.instance_eval{ @x = m; self} :
self
}
}
String.class_eval{
define_method(sel){
(m = self.instance_eval{ @x }) % n == 0 ?
(self+sel.to_s.capitalize).instance_eval{ @x = m; self} :
self
}
}
end
def_fizzBuzz :fizz, 3
def_fizzBuzz :buzz, 5
def_fizzBuzz :gizz, 7
p 1.fizz.buzz #=> 1
p 3.fizz.buzz #=> "Fizz"
p 5.fizz.buzz #=> "Buzz"
p 15.fizz.buzz #=> "FizzBuzz"
p 7.fizz.buzz.gizz #=> "Gizz"
p 21.fizz.buzz.gizz #=> "FizzGizz"
p 35.fizz.buzz.gizz #=> "BuzzGizz"
p 105.fizz.buzz.gizz #=> "FizzBuzzGizz"
p 105.fizz.gizz.buzz #=> "FizzGizzBuzz"
p 999.fizz.buzz #=> "Fizz"
p 1.fizz.buzz + 2 #=> 3
p (1.fizz.buzz + 2.buzz).fizz #=> "Fizz"
p 15.fizz.buzz.gizz + "XXX" #=> "FizzBuzzXXX"
ZGVmIGRlZl9maXp6QnV6eihzZWwsIG4pCiAgSW50ZWdlci5jbGFzc19ldmFsewogICAgZGVmaW5lX21ldGhvZChzZWwpewogICAgICAobSA9IHNlbGYpICUgbiA9PSAwID8KICAgICAgICBzZWwudG9fcy5jYXBpdGFsaXplLmluc3RhbmNlX2V2YWx7IEB4ID0gbTsgc2VsZn0gOgogICAgICAgIHNlbGYKICAgIH0KICB9CiAgU3RyaW5nLmNsYXNzX2V2YWx7CiAgICBkZWZpbmVfbWV0aG9kKHNlbCl7CiAgICAgIChtID0gc2VsZi5pbnN0YW5jZV9ldmFseyBAeCB9KSAlIG4gPT0gMCA/CiAgICAgICAgKHNlbGYrc2VsLnRvX3MuY2FwaXRhbGl6ZSkuaW5zdGFuY2VfZXZhbHsgQHggPSBtOyBzZWxmfSA6CiAgICAgICAgc2VsZgogICAgfQogIH0KZW5kCgpkZWZfZml6ekJ1enogOmZpenos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