Class: Array

Inherits:
Object
  • Object
show all
Defined in:
lib/chance/core_extensions.rb

Overview

end

Instance Method Summary collapse

Instance Method Details

#pick(percent) ⇒ Object



50
51
52
53
54
55
56
57
# File 'lib/chance/core_extensions.rb', line 50

def pick(percent)
  picks, percentage = [], percent.of(length).round
  while picks.length < percentage
    picks << random
    picks.uniq!
  end
  picks
end

#pick_about(percentage) ⇒ Object



59
60
61
62
63
# File 'lib/chance/core_extensions.rb', line 59

def pick_about(percentage)
  select do |element|
    percentage.chance.happens?
  end
end

#randomObject



46
47
48
# File 'lib/chance/core_extensions.rb', line 46

def random
  self[rand(length)]
end