Question: I'm writing the following dynamic function call in Groovy, and wanted to know if there is a cleaner way to perform the following:

```
    this.actions.each { a ->
        if (a.component) {
            this.context."${a.action}"(a.component)
        } else {
            this.context."${a.action}"()
        }
    }

```

The code for `a.action` could be a method that doesn't have any arguments, or it could accept a map. Is there a way to dynamically pass in `a.component`, or do I need some type of `if/else` conditional check for each method signature?

Answer: 
groovy objects has [`invokeMethod`](http://docs.groovy-lang.org/latest/html/api/groovy/lang/GroovyObject.html#invokeMethod(java.lang.String,java.lang.Object)) method that could hide the if

```
this.context.invikeMethod( a.action, a.component ? [a.component] : null )

```

`[a.component]` is in brackets because method could have 1,2,3... parameters
Without diving into meta-programming a lot, you could (mis-)use the `spread operator`

```
def a(){ 42 }
def a( i ){ i }

def b = 'a'
def c = [ 22 ]

assert 22 == "${b}"( *c )

c = []
assert 42 == "${b}"( *c )

```

Applied to your specific method:

```
this.context."${a.action}"( *( a.component ? [ a.component ] : [] ) )

```