Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR RUBY

ruby format string with parameters

# Rubocop issues with string formating
# Examples will print key/value pairs to console with padding for key
# => "name                 : value goes here"

# Cop success:
puts format('%-20<key>s : %<value>s', key: 'name', value: name)

# Cop failure: Style/FormatString: Favor format over String#%
puts '%-20s : %s' % ['name', name]

# Cop failure: Style/FormatStringToken: Prefer annotated tokens (like %<foo>s) over unannotated tokens (like %s)
puts format('%-20s : %s', 'name', name)
Source by github.com #
 
PREVIOUS NEXT
Tagged: #ruby #format #string #parameters
ADD COMMENT
Topic
Name
6+8 =