require 'contracts'
class A
include Contracts::Core
include Contracts::Builtin
end
class B < A
Contract Num => Num
def self.plus_two(num)
num + 2
end
end
class C < A
class << self
Contract Num => Num
def plus_two(num)
num + 2
end
end
end
classes B and C should be identical, however, Contracts raises an error for class C:
/Users/rk/.rvm/gems/ruby-2.2.3@soft24/gems/contracts-0.12.0/lib/contracts/engine/eigenclass.rb:38:in `validate!': In order to use contracts in singleton class, please include Contracts module in original class (Contracts::ContractsNotIncluded)
Example:
```ruby
class Example
include Contracts # this line is required
class << self
# you can use `Contract` definition here now
end
end
from /Users/rk/.rvm/gems/ruby-2.2.3@soft24/gems/contracts-0.12.0/lib/contracts/engine/base.rb:42:in `decorate'
from /Users/rk/.rvm/gems/ruby-2.2.3@soft24/gems/contracts-0.12.0/lib/contracts/decorators.rb:33:in `Contract'
from contracts_test.rb:18:in `singleton class'
from contracts_test.rb:17:in `<class:C>'
from contracts_test.rb:15:in `<main>'
Bare-minimum code to reproduce the problem:
classes
B
andC
should be identical, however,Contracts
raises an error for classC
: