Where in Ruby APIs do I find that Array#select takes a parameter?


In lesson Why Procs? we have:
* An array called: group_1
* The Proc: over_4_feet
* A select call: group_1.select( &over_4_feet )

We are passing in the parameter &over_4_feet to method select.

I check the APIs (API Ruby2.2 Array#select)

  (From Ruby API docs for Array#select)
  select { |item| block } → new_ary 
  select → Enumerator

and it doesn't appear to take any arguments. How do I read this to know that it can have arguments? Or am I missing something?


block is the Proc passed in to the method.


Thanks for the reply!
I guess I was expecting something like select(block) because of: select( &over_4_feet )
Whereas the docs showed select { |item| block } - with a space between "select" and "{".
A space between "select" and "(.." will cause an error.
The difference between the smooth bracket: "()" and squiggly brackets: "{}" confuses me in this API case.
Can you explain it to me? Any help appreciated.


In many language, () indicates an argument of parameter list; {} indicates a code block or a hash (in JS an object, in Python a dictionary, &c.).

The description you are seeing in the docs is pseudo code. select invokes the block and operates on the array in currect execution context (the one it is called upon).


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.