edgecase/ruby_koans — pull request #68 by liuhenry (2012-01-22 08:40:41+00:00)
Title: Fixed color support in OS X

use_colors? doesn't work correctly in OS X. Originally, this was:

``` ruby
if ENV['ANSI_COLOR'].nil?
! using_windows?
end
```
An exception was added if the win32console gem was installed.

``` ruby
if ENV['ANSI_COLOR'].nil?
if using_windows?
using_win32console
end
else
...
```
However, if ENV['ANSI_COLOR'] is not defined (like on OS X), this breaks since:

``` ruby
def using_win32console
defined? Win32::Console
end
```
returns nil if not true. Thus, another condition is necessary for OS X. This restores the originally functionality while preserving the win32console color usage:

``` ruby
def use_colors?
return false if ENV['NO_COLOR']
if ENV['ANSI_COLOR'].nil?
if using_windows?
using_win32console
else
return true
end
else
ENV['ANSI_COLOR'] =~ /^(t|y)/i
end
end
```