call_user_func_array
-
In Ruby we use
Object#sendto invoke a method by name at runtime. The first argument is the name of the method we’re calling, and the rest is a variable list of arguments to send to that method similar tocall_user_funcin PHP. We can pass in array of arguments similar to that incall_user_func_arrayby prefixing the array argument with a glob operator (*). This operator will expand the array to be passed in as variable arguments.PHP
function titleize($value, $delim='-') { return strtolower(str_replace(' ', $delim, $value)); } $args = array('my post title', '-'); $result = call_user_func_array('titleize', $args); var_export($result); // => my-blog-post
Ruby
def titleize(value, delim='-') value.gsub(' ', delim).downcase end args = ["my post title", '-'] send(:titleize, *args) # => my-blog-post
see also
Looking for Rails or PHP web application development, integration, and training?
Rails for PHP is brought to you by Maintainable Software. Get custom web applications and personalized training from the authors of the book and website.

