userqwert userqwert - 7 months ago 36
Ruby Question

ruby api documentation, how to read

I don't know what this equates to in Ruby, as I've not come across nested arguments before:

open(filename [, mode [, perm]] [, opt]) → file

How do I pass these three arguments?


It's a shorthand way of describing many variants of the same function.

The square brackets indicate that that portion is optional. So in this instance it means you can use:

open(filename, mode)
open(filename, mode, perm)
open(filename, mode, opt)
open(filename, opt)

Perm is within two square brackets which means it's optional if mode is used but can't be used without mode.