Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 52 lines (45 sloc) 0.717 kB
aaaed22 @oneup the best snippets from overall kyoto development
authored
1 class Class
2 def direct_descendents
3 result = []
4 ObjectSpace.each_object( Class ) do |c|
5 result << c if c.superclass == self
6 end
7 return result
8 end
9 end
10
11 module NamedRandom
12 def randomly_between(range)
13 range.begin + rand*(range.end-range.begin)
14 end
15
16 def with_probability(p)
17 yield if (rand <= p)
18 end
19 end
20
21 module NamedFractions
22 def half
23 0.5
24 end
25
26 def third
27 1.0/3
28 end
29
30 def quarter
31 0.25
32 end
33 end
34
35 module Timer
36 include NamedFractions
37 def after(duration)
38 Thread.new do
39 sleep duration.to_f
40 yield
41 end
42 end
43
44 def every(duration)
45 Thread.new do
46 while true
47 yield
48 sleep duration.to_f
49 end
50 end
51 end
52 end
Something went wrong with that request. Please try again.