add 'String#%'.

This commit is contained in:
Tomoyuki Sahara
2014-06-03 10:55:26 +09:00
committed by Yukihiro "Matz" Matsumoto
parent b81f0d0ffb
commit fe9f3fdd20
2 changed files with 16 additions and 2 deletions
+9
View File
@@ -0,0 +1,9 @@
class String
def %(args)
if args.is_a? Array
sprintf(self, *args)
else
sprintf(self, args)
end
end
end
+7 -2
View File
@@ -1,3 +1,8 @@
##
# Kernel#sprintf Kernel#format Test
#assert('Kernel.sprintf') do
#end
assert('String#%') do
assert_equal "one=1", "one=%d" % 1
assert_equal "1 one 1.0", "%d %s %3.1f" % [ 1, "one", 1.01 ]
assert_equal "123 < 456", "%{num} < %<str>s" % { num: 123, str: "456" }
end