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

c - Compilation of a code: unkown type name string -

java - Bypassing "final local variable defined in an enclosing type" -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -