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...

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

1 Comment

One more question, how am I gonna access the row length of the parameter.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.