You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Your functionsdeftest1puts"test 1"enddeftest2puts"test 2"enddeftest3puts"test 3"end# put your functions in an array using the method function and a symbol.arr=[method(:test1),method(:test2),method(:test3)]# call each method as you map over itarr.map{ |method| method.call}
Another way would be to store a Lambda or Proc to do the task.
# using Proctest1=Proc.new{puts"test 1"}test2=Proc.new{puts"test 2"}test3=Proc.new{puts"test 3"}arr=[test1,test2,test3]arr.map{ |method| method.call}# using Lamdastest1=lambda{puts"test 1"}test2=lambda{puts"test 2"}test3=lambda{puts"test 3"}arr=[test1,test2,test3]arr.map{ |method| method.call}