ruby - I don't know how to call a random method from an existing method -



ruby - I don't know how to call a random method from an existing method -

for example, have class 4 methods. in 4th method want phone call 1 random method.

for example, method can phone call "first", "second" or "third"

class test def first puts "1" end def sec puts "2" end def 3rd puts "3" end def end end test = test.new test.some

class test def first puts "1" end def sec puts "2" end def 3rd puts "3" end def public_send (self.class.instance_methods(false) - [__method__]).sample end end test = test.new test.some # >> 1

ruby random methods

Comments

Popular posts from this blog

php - Edges appear in image after resizing -

ios8 - iOS custom keyboard - preserve state between appearances -

Delphi change the assembly code of a running process -