Merge branch 'iij-pr-string-percent'

This commit is contained in:
Yukihiro "Matz" Matsumoto
2014-06-03 16:34:45 +09:00
2 changed files with 16 additions and 2 deletions
+9
View File
@@ -0,0 +1,9 @@
class String
def %(args)
if args.is_a? Hash
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