开发者

How to declare an array parameter in Rails 3?

开发者 https://www.devze.com 2023-02-17 03:37 出处:网络
guys. I tried this code: def trap_check开发者_StackOverflow社区(payroll[][], timelive[][]) . . .

guys. I tried this code:

 def trap_check开发者_StackOverflow社区(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...


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
0

精彩评论

暂无评论...
验证码 换一张
取 消