Created
August 22, 2014 08:45
-
-
Save Integralist/a9b12a7a3db9f9ca11ba to your computer and use it in GitHub Desktop.
Ruby string formatting functionality (like PHP's sprintf)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"foo-%s-baz" % "bar" # => "foo-bar-baz" | |
"foo-%s-baz" % 123 # => "foo-123-baz" |
kenoir
commented
Aug 22, 2014
Further:
"foo-%s,%s" % Array.new(2) { |i| i + 1}
def sprintf( text, *args )
args.each do |arg|
text['%s'] = arg
end
return text
end
puts sprintf( "ahmed %s work %s", "ali", "home" )``
Return
ahmed ali work home
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment