Module: Contracts::ClassMethods

Defined in:
lib/contracts.rb,
lib/contracts.rb,
lib/contracts.rb,
lib/contracts.rb

Instance Method Summary collapse

Instance Method Details

#Expects(expectation) ⇒ Object



161
162
163
164
# File 'lib/contracts.rb', line 161

def Expects(expectation)
  expect! expectation => Hash
  Contracts::Expects.new(expectation)
end

#method_added(name) ⇒ Object



94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/contracts.rb', line 94

def method_added(name)
  if annotations = Contracts.consume_current_contracts
    method = instance_method(name)
    annotated_method = Contracts::AnnotatedMethod.new(method, annotations)

    define_method name do |*args, &blk|
      annotated_method.invoke self, *args, &blk
    end
  end

  super
end

#NothrowObject



194
195
196
# File 'lib/contracts.rb', line 194

def Nothrow
  Contracts::Nothrows.new
end

#Returns(expectation) ⇒ Object



182
183
184
# File 'lib/contracts.rb', line 182

def Returns(expectation)
  Contracts::Returns.new(expectation)
end

#singleton_method_added(name) ⇒ Object



79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/contracts.rb', line 79

def singleton_method_added(name)
  if annotations = Contracts.consume_current_contracts
    method = singleton_method(name)
    annotated_method = Contracts::AnnotatedMethod.new(method, annotations)

    klass = self

    define_singleton_method name do |*args, &blk|
      annotated_method.invoke klass, *args, &blk
    end
  end

  super
end