class ParaDice::Results::AndKeep
Results
class to implement a roll 5 and keep 3 style of play
Constants
- DEFAULT_SORT_BY
default sort order. passed to sort_by. defaults to a simple pass through
Attributes
default_keep[RW]
@!attribute [rw] :default_keep
@return [Fixnum] the default number of dice to keep
@!attribute [rw] :default_low_results
@return [Boolean] keep dice off of the low end of the order. false by default
@!attribute [rw] :default_sort_by
@return [Proc] the sort by block defaults to passing the object through to sort
default_low_results[RW]
@!attribute [rw] :default_keep
@return [Fixnum] the default number of dice to keep
@!attribute [rw] :default_low_results
@return [Boolean] keep dice off of the low end of the order. false by default
@!attribute [rw] :default_sort_by
@return [Proc] the sort by block defaults to passing the object through to sort
default_sort_by[RW]
@!attribute [rw] :default_keep
@return [Fixnum] the default number of dice to keep
@!attribute [rw] :default_low_results
@return [Boolean] keep dice off of the low end of the order. false by default
@!attribute [rw] :default_sort_by
@return [Proc] the sort by block defaults to passing the object through to sort
Public Class Methods
new(default_keep = nil)
click to toggle source
@param [Regex,String] default_keep
# File lib/para_dice/results/and_keep.rb, line 18 def initialize(default_keep = nil) @default_keep = default_keep end
Public Instance Methods
resolve(faces, keep = default_keep, low_results = false, &blk)
click to toggle source
@param [Array<#to_s>] faces @param [Regex,String] keep default: default_keep
@param [Boolean] low_results if true take the bottom of the order @yield [obj] provides obj to call methods on to determine value for use
in Array.order_by. Numbers sort easy, names are trickier
@return [Array<String>]
# File lib/para_dice/results/and_keep.rb, line 28 def resolve(faces, keep = default_keep, low_results = false, &blk) results_method = low_results ? :first : :last if block_given? faces.sort_by(&blk).to_a.send(results_method, keep) else faces.sort_by(&default_sort_by).to_a.send(results_method, keep) end end