Skip to content
Browse files

Replace logical expressions with ENV#fetch in Random class

  • Loading branch information...
1 parent 4085758 commit 4a9afc0437930f74dddab76807ce8561cbbb5295 @txus committed Feb 12, 2012
Showing with 7 additions and 8 deletions.
  1. +7 −8 lib/mutant/random.rb
View
15 lib/mutant/random.rb
@@ -3,24 +3,23 @@ class Random
ALLOWED_SYMBOL_CHARACTERS = Array('a'..'z') + Array('A'..'Z')
def self.string
- ENV['RANDOM_STRING'] or
- Array.new(rand(50)) { rand(126).chr }.join
+ ENV.fetch('RANDOM_STRING') {
+ Array.new(rand(50)) { rand(126).chr }.join
+ }
end
def self.symbol
- ( ENV['RANDOM_SYMBOL'] or
+ ENV.fetch('RANDOM_SYMBOL') {
Array.new(rand(50).next) { ALLOWED_SYMBOL_CHARACTERS.choice }.join
- ).to_sym
+ }.to_sym
end
def self.fixnum
- ENV['RANDOM_FIXNUM'] or
- rand(100)
+ ENV.fetch('RANDOM_FIXNUM') { rand(100) }
end
def self.float
- ENV['RANDOM_FLOAT'] or
- (rand(100) + 0.5)
+ ENV.fetch('RANDOM_FLOAT') { (rand(100) + 0.5) }
end
def self.range

0 comments on commit 4a9afc0

Please sign in to comment.
Something went wrong with that request. Please try again.