How is a method "prototype" in ruby documentation interpreted? -


for example, in rails api following appears:

form_tag(url_for_options = {}, options = {}, &block)  

coming c++/java background, suggests 3 arguments required: 2 hashes , block. yet there numerous examples of method being used less 3 arguments , first argument taking form of string. how method template specify characteristics/type of each argument , arguments required? there summary documentation somewhere describing conventions used describe how invoke such methods?

there no prototypes in usual sense. in example

form_tag(url_for_options = {}, options = {}, &block) 

the form_tag method expects maximum of 2 parameters, because defaults supplied both of them can called without parameters @ all. ruby raises argumenterror if method called more arguments have been specified, or fewer arguments there parameters no default.

the type of default parameter values has no bearing on may passed when method called, , call form_tag(math::pi, false), while unlikely useful, compile fine.

specifying block in formal parameters has effect of giving named access block supplied in call. more appropriate execute block , pass values , using yield within method. block always optional when method called.


Comments