Ruby’s Exclamations: A Dream Come True
After writing the post about exclamation mark methods in Ruby yesterday evening, I couldn’t get to sleep (lesson learned: don’t go straight to bed after blogging). My mind was still churning away over the whole issue. And just before I fell asleep, in the short period of time when a lucid state of geniality bordering on insanity sometimes befalls you, when either the greatest ideas or the worst flops come to you — I dreamed up this code.
srand Time.now.to_i
class Ruby
S = ['yes', 'no', 'absolutely not',
'of course', 'you already know', 'of course not',
'who knows?', 'I guess so...', 'I guess not...',
'maybe', 'perhaps', 'certainly not',
'positively so', 'try google', 'who cares?',
'why not?', 'the answer is in your heart',
'we may never know for sure']
def self.exclamation_mark!
@@r = rand
Ruby
end
def self.is_redundant?
q = @@r * S.size
S[q]
end
end
puts Ruby.exclamation_mark!.is_redundant?
2006-01-23. No responses.