Class: Random
- Inherits:
-
Object
- Object
- Random
- Extended by:
- RandomData::Booleans, RandomData::ContactInfo, RandomData::Dates, RandomData::Locations, RandomData::Names, RandomData::Numbers, RandomData::Text
- Defined in:
- lib/random_data.rb
Class Method Summary collapse
-
.method_missing(methodname) ⇒ Object
Looks for a file with the name methodname.dat, reads the lines from that file, then gives you a random line from that file Will also search your load path for the file.
Methods included from RandomData::ContactInfo
email, international_phone, phone
Methods included from RandomData::Dates
Methods included from RandomData::Locations
address_line_1, address_line_2, city, country, state, state_full, zipcode
Methods included from RandomData::Names
Methods included from RandomData::Text
Class Method Details
.method_missing(methodname) ⇒ Object
Looks for a file with the name methodname.dat, reads the lines from that file, then gives you a random line from that file Will also search your load path for the file. Raises an error if it can’t find the file.
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/random_data.rb', line 24 def self.method_missing(methodname) thing = "#{methodname}.dat" filename = find_path(thing) if filename.nil? super else array = [] File.open(filename, 'r') { |f| array = f.read.split(/[\r\n]+/) } return array.rand end end |