Skip to content

Commit

Permalink
Actually use prng passed to GamesDice.create
Browse files Browse the repository at this point in the history
  • Loading branch information
Neil-Aframe committed May 27, 2014
1 parent 5323c02 commit b5bebe0
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# GamesDice Changelog

## 0.3.11 ( 26 May 2014 )

* Bugfix. Actually use custom PRNG passed to GamesDice.create or GamesDice::Bunch.new

## 0.3.10 ( 29 July 2013 )

* Non-functional changes to improve code quality metrics on CodeClimate
Expand Down
5 changes: 4 additions & 1 deletion lib/games_dice.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ module GamesDice
#
def self.create dice_description, prng = nil
parsed = @@parser.parse( dice_description )
GamesDice::Dice.new( parsed[:bunches], parsed[:offset], prng )
if prng
parsed[:bunches].each { |bunch| bunch.merge!( :prng => prng ) }
end
GamesDice::Dice.new( parsed[:bunches], parsed[:offset] )
end
end
2 changes: 1 addition & 1 deletion lib/games_dice/bunch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def initialize( options )
keep_mode_from_hash( options )

if options[:prng]
raise ":prng does not support the rand() method" if ! prng.respond_to?(:rand)
raise ":prng does not support the rand() method" if ! options[:prng].respond_to?(:rand)
end

if options[:rerolls] || options[:maps]
Expand Down
2 changes: 1 addition & 1 deletion lib/games_dice/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module GamesDice
VERSION = "0.3.10"
VERSION = "0.3.11"
end
7 changes: 7 additions & 0 deletions spec/readme_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,15 @@

it "takes an optional parameter 'prng', which if provided it should be an object that has a method 'rand( integer )'" do
prng = TestPRNG.new

d = GamesDice.create '3d6', prng
d.is_a?( GamesDice::Dice ).should be_true

(0..5).each do |dresult|
prng.stub( :rand ) { dresult }
expect( prng ).to receive(:rand).with(6)
d.roll.should == (dresult + 1) * 3
end
end
end # describe '#create'

Expand Down

0 comments on commit b5bebe0

Please sign in to comment.