You can save yourself some CPU cycles by pre-compiling the list of
available methods as a class instance variable:
class Mutating
...
@mutations = instance_methods.grep(/Mutation$/)
class << self
attr_reader :mutations
end
def mutation
send(self.class.mutations.sample)
end
end
Simon
>> First of all you can save typing by removing "self.". Then you should
>> replace #shuffle![0] with #sample:
>>
>> send(methods.select!{|element| element.to_s.end_with?("Mutation")}.sample)
>>
>> If you like you can strip this down even further by using regular
>> expressions because those happen to work with Symbols as well:
>>
>> send(methods.grep(/Mutation\z/).sample)
>>
>> :-)
>>
>> Kind regards
>>
>> robert
>>
>> --
>> remember.guy do |as, often| as.you_can - without end
>> http://blog.rubybestpractices.com/
>>
>
>