Module: Lexdrill::Rand
- Defined in:
- lib/lexdrill/rand.rb
Overview
Global "how often to actually show a word" setting, applied by
drill next itself (both automatic hook-triggered calls and manual
invocations respect it equally). Lives at ~/.drill.rand as a plain
integer; defaults to 1 (show every time).
Constant Summary collapse
- PATH =
File.join(Dir.home, ".drill.rand")
- DEFAULT =
1
Class Method Summary collapse
- .set(denominator) ⇒ Object
-
.skip? ⇒ Boolean
True with probability (n-1)/n: "skip this show".
- .value ⇒ Object
Class Method Details
.set(denominator) ⇒ Object
18 19 20 |
# File 'lib/lexdrill/rand.rb', line 18 def self.set(denominator) File.write(PATH, denominator.to_s) end |
.skip? ⇒ Boolean
True with probability (n-1)/n: "skip this show".
23 24 25 26 27 28 |
# File 'lib/lexdrill/rand.rb', line 23 def self.skip? denominator = value return false if denominator <= 1 Kernel.rand(denominator) != 0 end |