Ruby empty parameter in function -


i'm trying enqueue various functions in generic way code :

{ object.const_get(object_name).new(job[:params]||={}).delay(:queue => queue).send(method_name)} 

job hash name, objects parameters etc...

my problem in case :

class foo   def initialize     puts 'bar'   end end 

foo doesn't take parameters instanciation.

so if use previous line foo object_name i'll error :

argumenterror: wrong number pf arguments (1 0) 

and absolutly don't want write :

if job.has_key?[:param]   object.const_get(object_name).new(job[:params]||={}).delay(:queue => queue).send(method_name) else   object.const_get(object_name).new().delay(:queue => queue).send(method_name) end 

what write instead of job[:params]||={} works every case?

thanks in advance.

you can achieve using foo.send , using array.

for instance

object.   const_get(object_name).   send(*(job.has_key?(:param) ? ['new', job[:param]] : ['new']))... 

i think not worth , if statement easier on eyes.


Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -