ku1ik / rainbow

Ruby gem for colorizing printed text on ANSI terminals
MIT License
813 stars 68 forks source link

Fix for frozen strings #12

Closed fcoury closed 12 years ago

fcoury commented 12 years ago

Fixes the problem when adding colors to frozen strings:

1.8.7 :006 > x="a"
 => "a" 
1.8.7 :007 > x.color(:yellow)
 => "\e[33ma\e[0m" 
1.8.7 :009 > x.freeze
 => "a" 
1.8.7 :010 > x.color(:yellow)
TypeError: can't modify frozen string
  from /Users/fcoury/.rvm/gems/ree-1.8.7-2011.12/gems/rainbow-1.1.3/lib/rainbow.rb:91:in `insert'
  from /Users/fcoury/.rvm/gems/ree-1.8.7-2011.12/gems/rainbow-1.1.3/lib/rainbow.rb:91:in `wrap_with_code'
  from /Users/fcoury/.rvm/gems/ree-1.8.7-2011.12/gems/rainbow-1.1.3/lib/rainbow.rb:33:in `color'
  from (irb):10
ku1ik commented 12 years ago

That looks great, thanks. I'll merge it and release new gem tomorrow.