Thursday, 15 March 2012

ruby - How to pass a method as a string and call it -



ruby - How to pass a method as a string and call it -

i have proc so

boxer = proc.new { | box, goal | puts " [#{ box }] #{ goal }" }

and phone call so

boxer[ 'x', goal ]

i incorperate ansi escape codes alter color want able pass in string , have print color out new boxer this

boxer = proc.new { |box, goal, color | puts " [#{ box }] #{ goal }".color }

and want phone call so

boxer[ 'x', goal, 'red' ]

i using colorize gem still can't proc deed want have tried eval , couple other things.

if understand correctly, try

boxer = proc.new { |box, goal, color | puts " [#{ box }] #{ goal }".send(color) }

ruby

No comments:

Post a Comment