Commit fe9f3fdd authored by Tomoyuki Sahara's avatar Tomoyuki Sahara Committed by Yukihiro "Matz" Matsumoto

add 'String#%'.

parent b81f0d0f
class String
def %(args)
if args.is_a? Array
sprintf(self, *args)
else
sprintf(self, args)
end
end
end
##
# 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
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment