Skip to content

Commit

Permalink
Merged master
Browse files Browse the repository at this point in the history
  • Loading branch information
tj committed May 4, 2009
1 parent fb736ba commit 2e30a01
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 10 deletions.
4 changes: 2 additions & 2 deletions lib/commander/user_interaction.rb
Expand Up @@ -114,8 +114,8 @@ def method_missing meth, *args, &block
##
# Substitute _hash_'s keys with their associated values in _str_.

def self.replace_tokens str, hash
hash.inject(str) { |str, (key, value)| str.gsub ":#{key}", value.to_s }
def self.replace_tokens str, hash #:nodoc:
hash.inject(str.dup) { |str, (key, value)| str.gsub! ":#{key}", value.to_s }
end

##
Expand Down
9 changes: 1 addition & 8 deletions spec/ui_spec.rb
Expand Up @@ -3,16 +3,9 @@

describe ".replace_tokens" do
it "should replace tokens within a string, with hash values" do
result = Commander::UI.replace_tokens 'Welcome :name, enjoy your :object', :name => 'TJ', :object => 'cookie'
result = Commander::UI.replace_tokens 'Welcome :name, enjoy your :object'.freeze, :name => 'TJ', :object => 'cookie'
result.should == 'Welcome TJ, enjoy your cookie'
end

it "should not mutate the string passed" do
string = 'Oh I will enjoy my :object'
result = Commander::UI.replace_tokens string, :object => 'cookies'
result.should == 'Oh I will enjoy my cookies'
string.should == 'Oh I will enjoy my :object'
end
end

end

0 comments on commit 2e30a01

Please sign in to comment.