-
-
Save stemar/a9b038b53005cf00922dc0455c97047a to your computer and use it in GitHub Desktop.
Replace a string's placeholders with the provided key/value pairs
This file contains hidden or 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
| class String | |
| def p(**args) | |
| gsub(/:[\w]*/){|match| args[match[1..-1].to_sym] || match} | |
| end | |
| end |
This file contains hidden or 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
| "This :code contains :placeholders".p(:code=>"sentence", :placeholders=>"strings") | |
| # => "This sentence contains strings" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment