Module: CARPS::Dice
- Defined in:
- lib/carps/mod/dice.rb
Defined Under Namespace
Classes: D
Class Method Summary collapse
-
.comparison_to_proc(compare, other) ⇒ Object
When compare is one of.
-
.rfloat(min, max) ⇒ Object
Random floating point number between min and max.
-
.rint(min, max) ⇒ Object
Random integer between min and max.
Instance Method Summary collapse
-
#d(i) ⇒ Object
Create a new dice.
Class Method Details
.comparison_to_proc(compare, other) ⇒ Object
When compare is one of
:<, :<=, :==, :>, :>=
and other is an integer
Return a proc which takes an argument a and does
a compare other
341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 |
# File 'lib/carps/mod/dice.rb', line 341 def Dice::comparison_to_proc compare, other cmp = nil case compare when :< cmp = lambda {|a| a < other} when :<= cmp = lambda {|a| a <= other} when :== cmp = lambda {|a| a == other} when :>= cmp = lambda {|a| a >= other} when :> cmp = lambda {|a| a > other} end cmp end |
.rfloat(min, max) ⇒ Object
Random floating point number between min and max
28 29 30 31 32 |
# File 'lib/carps/mod/dice.rb', line 28 def Dice::rfloat min, max diff = max - min r = rand * diff r + min end |
.rint(min, max) ⇒ Object
Random integer between min and max
23 24 25 |
# File 'lib/carps/mod/dice.rb', line 23 def Dice::rint min, max rfloat(min - 0.5, max + 0.5).round end |