```ruby
require 'enumerator'

begin
  require 'generator' # 1.8.7
rescue LoadError
end

module Combinatorics
  # auto-detects the `Generator` class.
  Generator = if defined?(::Enumerator::Generator) # 1.9
                ::Enumerator::Generator
              elsif defined?(::Generator) # 1.8.7
                ::Generator
              else
                raise("unable to find the Generator class")
              end
end
```

Test for ::Generator first, to prevent warnings on JRuby.
user
```ruby
require 'enumerator'
require 'generator' if RUBY_VERSION < '1.9'

module Combinatorics
  # auto-detects the `Generator` class.
  Generator = if defined?(::Generator) # 1.8.7
                ::Generator
              elsif defined?(::Enumerator::Generator) # 1.9
                ::Enumerator::Generator
              else
                raise("unable to find the Generator class")
              end
end
```
assistant