PageRenderTime 55ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/puppet/module-common/lib/puppet/parser/functions/gsub.rb

https://github.com/gustavosoares/puppet-examples
Ruby | 21 lines | 11 code | 1 blank | 9 comment | 1 complexity | b57dc734e171a9aa3725ec39d4231e99 MD5 | raw file
  1. #
  2. # A thin wrapper around the ruby gsub function.
  3. #
  4. # gsub($string, $pattern, $replacement)
  5. #
  6. # will replace all occurrences of $pattern in $string with $replacement.
  7. # $string can be either a single value or an array. In the latter case, each
  8. # element of the array will be processed in turn.
  9. #
  10. module Puppet::Parser::Functions
  11. newfunction(:gsub, :type => :rvalue) do |args|
  12. if args[0].is_a?(Array)
  13. args[0].collect do |val|
  14. val.gsub(/#{args[1]}/, args[2])
  15. end
  16. else
  17. args[0].gsub(/#{args[1]}/, args[2])
  18. end
  19. end
  20. end