mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
add 'String#%'.
This commit is contained in:
committed by
Yukihiro "Matz" Matsumoto
parent
b81f0d0ffb
commit
fe9f3fdd20
@@ -0,0 +1,9 @@
|
||||
class String
|
||||
def %(args)
|
||||
if args.is_a? Array
|
||||
sprintf(self, *args)
|
||||
else
|
||||
sprintf(self, args)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user