0

guys. I tried this code:

 def trap_check(payroll[][], timelive[][])
 .
 .
 .
 end

I was trying to create a function that accepts 2-dimensional array as parameters. I was having this error:


 syntax error, unexpected '[', expecting ')'
    def trap_check(payroll[][], timelive[][])

Can somebody pls tell me how to do it the right way??? Pls help...

johan
  • 2,319
  • 9
  • 27
  • 37

1 Answers1

2

In Ruby you don't declare types, so your function would just be:

def trap_check(payroll, timelive)
# code
end

And you might call it as such

trap_check([[1,2,3,4],[5,6]], [[1,1,1,1],[2,2,2,2]])

To verify if payroll is infact an array, you can just do:

payroll.is_a?(Array) #=> returns true or false
Mike Lewis
  • 63,433
  • 20
  • 141
  • 111