diff options
author | Ken Barber <ken@bob.sh> | 2011-07-29 00:10:31 +0100 |
---|---|---|
committer | Ken Barber <ken@bob.sh> | 2011-07-29 00:10:31 +0100 |
commit | ce48eb6e7a76f74e1f61c76ac3b185031c40772b (patch) | |
tree | dbb7d442fe1678a7bb208b395e0acf58e7357d5a | |
parent | 7d6ae5d57ce45ff1293f02b90c816a7f938a3af6 (diff) | |
download | puppet-stdlib-ce48eb6e7a76f74e1f61c76ac3b185031c40772b.tar.gz puppet-stdlib-ce48eb6e7a76f74e1f61c76ac3b185031c40772b.tar.bz2 |
Allow sort for strings.
-rw-r--r-- | lib/puppet/parser/functions/sort.rb | 8 | ||||
-rw-r--r-- | spec/unit/parser/functions/sort_spec.rb | 5 |
2 files changed, 12 insertions, 1 deletions
diff --git a/lib/puppet/parser/functions/sort.rb b/lib/puppet/parser/functions/sort.rb index 54a4018..49ca20a 100644 --- a/lib/puppet/parser/functions/sort.rb +++ b/lib/puppet/parser/functions/sort.rb @@ -12,7 +12,13 @@ module Puppet::Parser::Functions "given #{arguments.size} for 1") end - arguments[0].sort + value = arguments[0] + + if value.is_a?(Array) then + value.sort + elsif value.is_a?(String) then + value.split("").sort.to_s + end end end diff --git a/spec/unit/parser/functions/sort_spec.rb b/spec/unit/parser/functions/sort_spec.rb index da5db7a..fbe3073 100644 --- a/spec/unit/parser/functions/sort_spec.rb +++ b/spec/unit/parser/functions/sort_spec.rb @@ -23,4 +23,9 @@ describe "the sort function" do result.should(eq(['a','b','c'])) end + it "should sort a string" do + result = @scope.function_sort(["acb"]) + result.should(eq('abc')) + end + end |