Top Level Namespace
Defined Under Namespace
Modules: Bar, Contracts, Entitlements, Mod, ModuleContractExample, ModuleExample, ModuleWithContracts, RubyVersionCheck, Wrapper
Classes: A, B, BareOptionalContractUsed, Child, Contract, ContractBaseError, ContractError, EmptyCont, F, Foo, GenericExample, InvariantError, KlassWithModuleExample, MyBirthday, NotWrapped, Obj, ObjWithInvariants, ParamContractError, Parent, PatternMatchingError, PatternMatchingExample, ReturnContractError, SingletonClassExample, SingletonInheritanceExample, SingletonInheritanceExampleSubclass, Wrapped
Constant Summary
collapse
- C =
Contracts
- Baz =
1
Constants included
from Contracts
Contracts::VERSION
Contracts::Builtin::ArrayOf, Contracts::Builtin::SetOf
Instance Method Summary
collapse
Methods included from Contracts
extended, included
#attr_accessor_with_contract, #attr_reader_with_contract, #attr_writer_with_contract
Instance Method Details
#add(a, b) ⇒ Object
9
10
11
|
# File 'lib/contracts-ruby2/benchmarks/hash.rb', line 9
def add opts
opts[:a] + opts[:b]
end
|
#benchmark ⇒ Object
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/contracts-ruby2/benchmarks/io.rb', line 21
def benchmark
Benchmark.bm 30 do |x|
x.report "testing download" do
100.times do |_|
download(@urls.sample)
end
end
x.report "testing contracts download" do
100.times do |_|
contracts_download(@urls.sample)
end
end
end
end
|
#contracts_add(a, b) ⇒ Object
14
15
16
|
# File 'lib/contracts-ruby2/benchmarks/hash.rb', line 14
def contracts_add opts
opts[:a] + opts[:b]
end
|
#contracts_download(url) ⇒ Object
15
16
17
|
# File 'lib/contracts-ruby2/benchmarks/io.rb', line 15
def contracts_download url
open("http://www.#{url}").read
end
|
#download(url) ⇒ Object
10
11
12
|
# File 'lib/contracts-ruby2/benchmarks/io.rb', line 10
def download url
open("http://www.#{url}/").read
end
|
#explicit_add(a, b) ⇒ Object
18
19
20
21
22
23
24
25
26
|
# File 'lib/contracts-ruby2/benchmarks/hash.rb', line 18
def explicit_add opts
a = opts[:a]
b = opts[:b]
fail unless a.is_a?(Numeric)
fail unless b.is_a?(Numeric)
c = a + b
fail unless c.is_a?(Numeric)
c
end
|
#profile ⇒ Object
36
37
38
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/contracts-ruby2/benchmarks/io.rb', line 36
def profile
profilers = []
profilers << MethodProfiler.observe(Contract)
profilers << MethodProfiler.observe(Object)
profilers << MethodProfiler.observe(Contracts::MethodDecorators)
profilers << MethodProfiler.observe(Contracts::Decorator)
profilers << MethodProfiler.observe(Contracts::Support)
profilers << MethodProfiler.observe(UnboundMethod)
10.times do |_|
contracts_download(@urls.sample)
end
profilers.each { |p| puts p.report }
end
|
#ruby_prof ⇒ Object
50
51
52
53
54
55
56
57
58
|
# File 'lib/contracts-ruby2/benchmarks/io.rb', line 50
def ruby_prof
RubyProf.start
10.times do |_|
contracts_download(@urls.sample)
end
result = RubyProf.stop
printer = RubyProf::FlatPrinter.new(result)
printer.print(STDOUT)
end
|
#ruby_version ⇒ Object
8
9
10
|
# File 'lib/contracts-ruby2/spec/support.rb', line 8
def ruby_version
RUBY_VERSION.match(/\d+\.\d+/)[0].to_f
end
|
#with_enabled_no_contracts ⇒ Object
1
2
3
4
5
6
|
# File 'lib/contracts-ruby2/spec/support.rb', line 1
def with_enabled_no_contracts
no_contracts = ENV["NO_CONTRACTS"]
ENV["NO_CONTRACTS"] = "true"
yield
ENV["NO_CONTRACTS"] = no_contracts
end
|