Module: Contracts::ClassMethods

Includes:
Contracts
Defined in:
lib/contracts.rb,
lib/contracts/expects.rb,
lib/contracts/returns.rb,
lib/contracts/runtime.rb,
lib/contracts/nothrows.rb

Instance Method Summary collapse

Methods included from Contracts

consume_current_contracts, current_contracts, included

Instance Method Details

#Expects(expectation) ⇒ Object



42
43
44
45
# File 'lib/contracts/expects.rb', line 42

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

#method_added(name) ⇒ Object



128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/contracts.rb', line 128

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



15
16
17
# File 'lib/contracts/nothrows.rb', line 15

def Nothrow
  Contracts::Nothrows.new
end

#Returns(expectation) ⇒ Object



23
24
25
# File 'lib/contracts/returns.rb', line 23

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

#Runtime(expected_runtime, options = {}) ⇒ Object



44
45
46
# File 'lib/contracts/runtime.rb', line 44

def Runtime(expected_runtime, options = {})
  Contracts::Runtime.new expected_runtime, options
end

#singleton_method_added(name) ⇒ Object



113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/contracts.rb', line 113

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