Class: GenericExample

Inherits:
Object
  • Object
show all
Includes:
Contracts::Core
Defined in:
lib/contracts-ruby2/spec/fixtures/fixtures.rb,
lib/contracts-ruby2/spec/fixtures/fixtures.rb,
lib/contracts-ruby2/spec/fixtures/fixtures.rb,
lib/contracts-ruby3/spec/fixtures/fixtures.rb,
lib/contracts-ruby3/spec/fixtures/fixtures.rb,
lib/contracts-ruby3/spec/fixtures/fixtures.rb,
lib/contracts-ruby2/spec/ruby_version_specific/contracts_spec_1.9.rb,
lib/contracts-ruby2/spec/ruby_version_specific/contracts_spec_2.0.rb,
lib/contracts-ruby2/spec/ruby_version_specific/contracts_spec_2.1.rb,
lib/contracts-ruby3/spec/ruby_version_specific/contracts_spec_1.9.rb,
lib/contracts-ruby3/spec/ruby_version_specific/contracts_spec_2.0.rb,
lib/contracts-ruby3/spec/ruby_version_specific/contracts_spec_2.1.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Contracts::Core

common, extended, included

Class Method Details

.a_class_method(x) ⇒ Object



68
69
70
# File 'lib/contracts-ruby2/spec/fixtures/fixtures.rb', line 68

def self.a_class_method x
  x + 1
end

Instance Method Details

#and_test(x) ⇒ Object



256
257
# File 'lib/contracts-ruby2/spec/fixtures/fixtures.rb', line 256

def and_test(x)
end

#arg_then_splat(n, *vals) ⇒ Object



217
218
219
# File 'lib/contracts-ruby2/spec/fixtures/fixtures.rb', line 217

def arg_then_splat(n, *vals)
  vals.map { |v| v * n }
end

#array_complex_contracts(data) ⇒ Object



148
149
# File 'lib/contracts-ruby2/spec/fixtures/fixtures.rb', line 148

def array_complex_contracts(data)
end

#array_containing_foo(s) ⇒ Object



144
145
# File 'lib/contracts-ruby2/spec/fixtures/fixtures.rb', line 144

def array_containing_foo(s)
end

#bad_double(x) ⇒ Object



73
74
75
# File 'lib/contracts-ruby2/spec/fixtures/fixtures.rb', line 73

def bad_double(x)
  x * 2
end

#bool_test(x) ⇒ Object



304
305
# File 'lib/contracts-ruby2/spec/fixtures/fixtures.rb', line 304

def bool_test(x)
end

#complicated(a, b = true, *c, d, e:, f: 2, **g, &h) ⇒ Object



4
5
6
# File 'lib/contracts-ruby2/spec/ruby_version_specific/contracts_spec_2.1.rb', line 4

def complicated(a, b = true, *c, d, e:, f:2, **g, &h)
  h.call [h, g, f, e, d, c, b, a]
end

#constanty(num, nul) ⇒ Object



83
84
85
# File 'lib/contracts-ruby2/spec/fixtures/fixtures.rb', line 83

def constanty(num, nul)
  0
end

#default_args(x = 1) ⇒ Object



357
358
359
# File 'lib/contracts-ruby2/spec/fixtures/fixtures.rb', line 357

def default_args(x = 1)
  2
end

#do_call(&block) ⇒ Object



180
181
182
# File 'lib/contracts-ruby2/spec/fixtures/fixtures.rb', line 180

def do_call(&block)
  block.call
end

#double(x) ⇒ Object



78
79
80
# File 'lib/contracts-ruby2/spec/fixtures/fixtures.rb', line 78

def double(x)
  x * 2
end

#double_with_proc(x, &blk) ⇒ Object



222
223
224
225
# File 'lib/contracts-ruby2/spec/fixtures/fixtures.rb', line 222

def double_with_proc(x, &blk)
  blk.call(x * 2)
  nil
end

#enum_test(x) ⇒ Object



260
261
# File 'lib/contracts-ruby2/spec/fixtures/fixtures.rb', line 260

def enum_test(x)
end

#enumerable_descendant_test(enum) ⇒ Object



300
301
# File 'lib/contracts-ruby2/spec/fixtures/fixtures.rb', line 300

def enumerable_descendant_test(enum)
end

#eq_class_test(x) ⇒ Object



449
450
# File 'lib/contracts-ruby2/spec/fixtures/fixtures.rb', line 449

def eq_class_test(x)
end

#eq_module_test(x) ⇒ Object



453
454
# File 'lib/contracts-ruby2/spec/fixtures/fixtures.rb', line 453

def eq_module_test(x)
end

#eq_value_test(x) ⇒ Object



457
458
# File 'lib/contracts-ruby2/spec/fixtures/fixtures.rb', line 457

def eq_value_test(x)
end

#exactly_test(x) ⇒ Object



436
437
# File 'lib/contracts-ruby2/spec/fixtures/fixtures.rb', line 436

def exactly_test(x)
end

#fail_all(x) ⇒ Object



244
245
# File 'lib/contracts-ruby2/spec/fixtures/fixtures.rb', line 244

def fail_all(x)
end

#first_in_range_date(r) ⇒ Object



295
296
297
# File 'lib/contracts-ruby2/spec/fixtures/fixtures.rb', line 295

def first_in_range_date(r)
  r.first
end

#first_in_range_num(r) ⇒ Object



290
291
292
# File 'lib/contracts-ruby2/spec/fixtures/fixtures.rb', line 290

def first_in_range_num(r)
  r.first
end

#gives_max_value(hash) ⇒ Object



371
372
373
# File 'lib/contracts-ruby2/spec/fixtures/fixtures.rb', line 371

def gives_max_value(hash)
  hash.values.max
end

#hash_complex_contracts(data) ⇒ Object



112
113
# File 'lib/contracts-ruby2/spec/fixtures/fixtures.rb', line 112

def hash_complex_contracts(data)
end

#hash_containing_foo(s) ⇒ Object



140
141
# File 'lib/contracts-ruby2/spec/fixtures/fixtures.rb', line 140

def hash_containing_foo(s)
end

#hash_keywordargs(hash:) ⇒ Object



132
133
# File 'lib/contracts-ruby2/spec/fixtures/fixtures.rb', line 132

def hash_keywordargs(data)
end

#hello(name) ⇒ Object



88
89
# File 'lib/contracts-ruby2/spec/fixtures/fixtures.rb', line 88

def hello(name)
end

#id_(a) ⇒ Object



431
432
433
# File 'lib/contracts-ruby2/spec/fixtures/fixtures.rb', line 431

def id_ a
  a
end

#keyword_args_hello(name: "Adit", &block) ⇒ Object



12
13
14
# File 'lib/contracts-ruby2/spec/ruby_version_specific/contracts_spec_2.0.rb', line 12

def keyword_args_hello(name: "Adit", &block)
  "Hey, #{yield name}!"
end

#lambda_with_correct_returnObject



352
353
354
# File 'lib/contracts-ruby2/spec/fixtures/fixtures.rb', line 352

def lambda_with_correct_return
  lambda { |x| x.length }
end

#lambda_with_wrong_returnObject



347
348
349
# File 'lib/contracts-ruby2/spec/fixtures/fixtures.rb', line 347

def lambda_with_wrong_return
  lambda { |x| x }
end

#long_array_param_contracts(data) ⇒ Object



164
165
# File 'lib/contracts-ruby2/spec/fixtures/fixtures.rb', line 164

def long_array_param_contracts(data)
end

#long_array_return_contractsObject



176
177
# File 'lib/contracts-ruby2/spec/fixtures/fixtures.rb', line 176

def long_array_return_contracts
end

#map(arr, func) ⇒ Object



320
321
322
323
324
325
326
# File 'lib/contracts-ruby2/spec/fixtures/fixtures.rb', line 320

def map(arr, func)
  ret = []
  arr.each do |x|
    ret << func[x]
  end
  ret
end

#map_plain(arr, func) ⇒ Object



340
341
342
343
344
# File 'lib/contracts-ruby2/spec/fixtures/fixtures.rb', line 340

def map_plain(arr, func)
  arr.map do |x|
    func[x]
  end
end

#maybe_call(*vals, &block) ⇒ Object



185
186
187
188
# File 'lib/contracts-ruby2/spec/fixtures/fixtures.rb', line 185

def maybe_call(*vals, &block)
  block.call if block
  vals
end

#maybe_double(x) ⇒ Object



362
363
364
365
366
367
368
# File 'lib/contracts-ruby2/spec/fixtures/fixtures.rb', line 362

def maybe_double x
  if x.nil?
    nil
  else
    x * 2
  end
end

#method_with_range_contract(x) ⇒ Object



386
387
# File 'lib/contracts-ruby2/spec/fixtures/fixtures.rb', line 386

def method_with_range_contract(x)
end

#nat_test(x) ⇒ Object



236
237
# File 'lib/contracts-ruby2/spec/fixtures/fixtures.rb', line 236

def nat_test(x)
end

#nat_test_with_kwarg(foo: 10) ⇒ Object



9
10
# File 'lib/contracts-ruby2/spec/ruby_version_specific/contracts_spec_1.9.rb', line 9

def nat_test_with_kwarg(a_hash)
end

#neg_test(x) ⇒ Object



232
233
# File 'lib/contracts-ruby2/spec/fixtures/fixtures.rb', line 232

def neg_test(x)
end

#nested_array_complex_contracts(data) ⇒ Object



152
153
# File 'lib/contracts-ruby2/spec/fixtures/fixtures.rb', line 152

def nested_array_complex_contracts(data)
end

#nested_hash_complex_contracts(data) ⇒ Object



119
120
# File 'lib/contracts-ruby2/spec/fixtures/fixtures.rb', line 119

def nested_hash_complex_contracts(data)
end

#no_argsObject



308
309
310
# File 'lib/contracts-ruby2/spec/fixtures/fixtures.rb', line 308

def no_args
  1
end

#not_nil(x) ⇒ Object



272
273
# File 'lib/contracts-ruby2/spec/fixtures/fixtures.rb', line 272

def not_nil(x)
end

#num_or_string(x) ⇒ Object



248
249
# File 'lib/contracts-ruby2/spec/fixtures/fixtures.rb', line 248

def num_or_string(x)
end

#old_style_no_argsObject



315
316
317
# File 'lib/contracts-ruby2/spec/fixtures/fixtures.rb', line 315

def old_style_no_args
  2
end

#person(data) ⇒ Object



104
105
# File 'lib/contracts-ruby2/spec/fixtures/fixtures.rb', line 104

def person(data)
end

#person_keywordargs(name: "name", age: 10) ⇒ Object



123
124
# File 'lib/contracts-ruby2/spec/fixtures/fixtures.rb', line 123

def person_keywordargs(data)
end

#pos_test(x) ⇒ Object



228
229
# File 'lib/contracts-ruby2/spec/fixtures/fixtures.rb', line 228

def pos_test(x)
end

#pretty_gives_max_value(hash) ⇒ Object



376
377
378
# File 'lib/contracts-ruby2/spec/fixtures/fixtures.rb', line 376

def pretty_gives_max_value(hash)
  hash.values.max
end

#product(vals) ⇒ Object



276
277
278
279
280
# File 'lib/contracts-ruby2/spec/fixtures/fixtures.rb', line 276

def product(vals)
  vals.inject(1) do |acc, x|
    acc * x
  end
end

#product_from_set(vals) ⇒ Object



283
284
285
286
287
# File 'lib/contracts-ruby2/spec/fixtures/fixtures.rb', line 283

def product_from_set(vals)
  vals.inject(1) do |acc, x|
    acc * x
  end
end

#responds_test(x) ⇒ Object



264
265
# File 'lib/contracts-ruby2/spec/fixtures/fixtures.rb', line 264

def responds_test(x)
end

#send_test(x) ⇒ Object



268
269
# File 'lib/contracts-ruby2/spec/fixtures/fixtures.rb', line 268

def send_test(x)
end

#should_contain_foo(s) ⇒ Object



136
137
# File 'lib/contracts-ruby2/spec/fixtures/fixtures.rb', line 136

def should_contain_foo(s)
end

#show(x) ⇒ Object



240
241
# File 'lib/contracts-ruby2/spec/fixtures/fixtures.rb', line 240

def show(x)
end

#splat_then_arg(*vals, n) ⇒ Object



3
4
5
# File 'lib/contracts-ruby2/spec/ruby_version_specific/contracts_spec_1.9.rb', line 3

def splat_then_arg(*vals, n)
  vals.map { |v| v * n }
end

#splat_then_optional_named(*vals, repeat: 2) ⇒ Object



3
4
5
# File 'lib/contracts-ruby2/spec/ruby_version_specific/contracts_spec_2.0.rb', line 3

def splat_then_optional_named(*vals, repeat: 2)
  vals.map { |v| v * repeat }
end

#square(x) ⇒ Object



92
93
94
# File 'lib/contracts-ruby2/spec/fixtures/fixtures.rb', line 92

def square(x)
  x ** 2
end

#strict_person(data) ⇒ Object



108
109
# File 'lib/contracts-ruby2/spec/fixtures/fixtures.rb', line 108

def strict_person(data)
end

#sum(*vals) ⇒ Object



191
192
193
194
195
# File 'lib/contracts-ruby2/spec/fixtures/fixtures.rb', line 191

def sum(*vals)
  vals.inject(0) do |acc, val|
    acc + val
  end
end

#sum_three(vals) ⇒ Object



97
98
99
100
101
# File 'lib/contracts-ruby2/spec/fixtures/fixtures.rb', line 97

def sum_three(vals)
  vals.inject(0) do |acc, x|
    acc + x
  end
end

#tutorial_map(arr, func) ⇒ Object



329
330
331
332
333
334
335
# File 'lib/contracts-ruby2/spec/fixtures/fixtures.rb', line 329

def tutorial_map(arr, func)
  ret = []
  arr.each do |x|
    ret << func[x]
  end
  ret
end

#using_empty_contract(a) ⇒ Object



381
382
383
# File 'lib/contracts-ruby2/spec/fixtures/fixtures.rb', line 381

def using_empty_contract(a)
  a
end

#with_partial_sums(*vals, &blk) ⇒ Object



198
199
200
201
202
203
204
# File 'lib/contracts-ruby2/spec/fixtures/fixtures.rb', line 198

def with_partial_sums(*vals, &blk)
  sum = vals.inject(0) do |acc, val|
    blk[acc]
    acc + val
  end
  blk[sum]
end

#with_partial_sums_contracted(*vals, &blk) ⇒ Object



207
208
209
210
211
212
213
# File 'lib/contracts-ruby2/spec/fixtures/fixtures.rb', line 207

def with_partial_sums_contracted(*vals, &blk)
  sum = vals.inject(0) do |acc, val|
    blk[acc]
    acc + val
  end
  blk[sum]
end

#xor_test(x) ⇒ Object



252
253
# File 'lib/contracts-ruby2/spec/fixtures/fixtures.rb', line 252

def xor_test(x)
end