Module: NethackUtils::Rumor

Includes:
GetText
Included in:
NethackUtils
Defined in:
lib/nethack_utils/rumor.rb

Class Method Summary collapse

Class Method Details

.rumor(reliability = nil) ⇒ Object

Returns a randomly chosen rumor message.

Its reliability is detemined the optional reliability argument.

Arguments

  • reliability specifies the reliability(trueness) of the message in range [0,1].



15
16
17
18
19
20
# File 'lib/nethack_utils/rumor.rb', line 15

def rumor(reliability=nil)
  reliability ||= rand
  data_root = File.join(File.dirname(__FILE__), '..', '..', 'data')
  rumors_file = File.join(data_root, reliability < 0.5 ? _('rumors.tru') : _('rumors.fal'))
  open(rumors_file) {|io| io.lines.inject {|r, l| rand($.) < 1 ? l : r } }.chomp
end