mirror of https://github.com/tailix/libkernaux.git
Ruby: Add method KernAux.sprintf
This commit is contained in:
parent
b30a98d9b3
commit
9193b9e9ea
|
@ -20,6 +20,16 @@ module KernAux
|
|||
assert_do file, Integer(line), msg
|
||||
end
|
||||
|
||||
def self.sprintf(*args)
|
||||
args.map do |arg|
|
||||
if arg.is_a? Array
|
||||
sprintf1(*arg)
|
||||
else
|
||||
arg
|
||||
end
|
||||
end.join.freeze
|
||||
end
|
||||
|
||||
def self.sprintf1(format, arg = nil)
|
||||
if arg.nil?
|
||||
snprintf1(SPRINTF1_BUFFER_SIZE, format).first
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'spec_helper'
|
||||
|
||||
RSpec.describe KernAux, '.sprintf' do
|
||||
subject(:sprintf) { described_class.sprintf 'Hello, ', ['%s', 'World'], '!' }
|
||||
|
||||
it { is_expected.to be_instance_of String }
|
||||
it { is_expected.to be_frozen }
|
||||
it { is_expected.to eq 'Hello, World!' }
|
||||
end
|
Loading…
Reference in New Issue