This is not what he asked, if I understand his question correctly. I mean, send accepts a string or character as arg, and your solution is not. I donโt think there is a built-in method that will do what you want, but I hacked into a method that will be with the test.
require 'test/unit' class Example def multi_send(str) str.split('.').inject(self){|klass, method| klass.send(method) } end end class MyTest < Test::Unit::TestCase def test_multi_send a = Example.new methods = "class.to_s.downcase.chop!" assert a.multi_send(methods) == 'exampl' end end
brianthecoder
source share