Class: ParaDice::Bag
- Inherits:
-
Object
- Object
- ParaDice::Bag
- Defined in:
- lib/para_dice/bag.rb
Overview
Class to provide a convienent container for and roller of dice
Direct Known Subclasses
Instance Attribute Summary collapse
-
#default_readers ⇒ Array<#resolve>
Default: [].
-
#dice ⇒ Hash<String,Die>
Default: {}.
-
#name ⇒ String
Default: ‘Dice Bag’.
-
#rng ⇒ Random
Default: Random.new.
Instance Method Summary collapse
-
#add_die(die) ⇒ Object
add a die to the bag.
-
#get_cup(*dice_names) ⇒ Object
given an array of dice_names, create a Cup using them and default_readers @param(*dice_names) array of dice names.
-
#get_dice(*dice_names) ⇒ Object
get an array of dice from an array of dice names @param(*dice_names) array of dice names.
Instance Attribute Details
#default_readers ⇒ Array<#resolve>
Returns default: [].
18 |
# File 'lib/para_dice/bag.rb', line 18 attribute :default_readers, Array, default: [] |
#dice ⇒ Hash<String,Die>
Returns default: {}.
15 |
# File 'lib/para_dice/bag.rb', line 15 attribute :dice, Hash[String => Die], default: {} |
#name ⇒ String
Returns default: ‘Dice Bag’.
12 |
# File 'lib/para_dice/bag.rb', line 12 attribute :name, String, default: 'Dice Bag' |
#rng ⇒ Random
Returns default: Random.new.
21 |
# File 'lib/para_dice/bag.rb', line 21 attribute :rng, Random, default: ->(*a) { Random.new } |
Instance Method Details
#add_die(die) ⇒ Object
add a die to the bag
25 26 27 |
# File 'lib/para_dice/bag.rb', line 25 def add_die(die) dice[die.name] = die end |
#get_cup(*dice_names) ⇒ Object
given an array of dice_names, create a Cup using them and default_readers @param(*dice_names) array of dice names.
37 38 39 40 41 42 |
# File 'lib/para_dice/bag.rb', line 37 def get_cup(*dice_names) Cup.new(dice: get_dice(*dice_names), rng: rng, readers: default_readers ) end |
#get_dice(*dice_names) ⇒ Object
get an array of dice from an array of dice names @param(*dice_names) array of dice names.
31 32 33 |
# File 'lib/para_dice/bag.rb', line 31 def get_dice(*dice_names) dice_names.flatten.map { |die_name| dice[die_name.to_s] } end |