# Multi-def docs?

**URL:** <https://rubytalk.org/t/multi-def-docs/30717>\
**Category:** ruby-talk\
**Created:** [6 September 2006 17:35 UTC](https://rubytalk.org/t/multi-def-docs/30717 "2006-09-06T17:35:18Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![YAD](https://avatars.discourse-cdn.com/v4/letter/y/df705f/32.png) [@YAD](https://rubytalk.org/u/YAD)\
**Post date:** [6 September 2006 17:35 UTC](https://rubytalk.org/t/multi-def-docs/30717/1 "2006-09-06T17:35:18Z")

</div>

I thought Ruby allows you to define similar functions in parallel by putting the parts that differ together in square brackets. Is there some online documentation for that? I haven't been able to find it yet.

> **···**
>
> --  
> Yet another Dan

---

<div class="post-metadata">

**Author:** ![E\_S](https://avatars.discourse-cdn.com/v4/letter/e/3be4f8/32.png) [@E\_S](https://rubytalk.org/u/E_S)\
**Post date:** [6 September 2006 18:57 UTC](https://rubytalk.org/t/multi-def-docs/30717/2 "2006-09-06T18:57:46Z")

</div>

YAD wrote:

> I thought Ruby allows you to define similar functions in parallel by  
> putting the parts that differ together in square brackets. Is there  
> some online documentation for that? I haven't been able to find it yet.

If you mean something like this:

some\_method(arg1, arg2[, arg3[, arg4]]) =\> nil

It is just a documentation convention to indicate  
optional arguments. In RDoc files this only appears  
in methods defined in C because the call sequence  
is entered manually in the doc rather than being  
extracted from the code itself like with pure-Ruby.

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

**Author:** ![Robert\_K1](https://yyz1.discourse-cdn.com/flex029/user_avatar/rubytalk.org/robert_k1/32/1830_2.png) [@Robert\_K1](https://rubytalk.org/u/Robert_K1)\
**Post date:** [6 September 2006 21:00 UTC](https://rubytalk.org/t/multi-def-docs/30717/3 "2006-09-06T21:00:11Z")

</div>

YAD wrote:

> I thought Ruby allows you to define similar functions in parallel by putting the parts that differ together in square brackets. Is there some online documentation for that? I haven't been able to find it yet.

I have never heard of such a feature. This is certainly not in the core language. Maybe some extension or framework? How do you think does the syntax look like?

Kind regards

&nbsp;&nbsp;robert

---

<div class="post-metadata">

**Author:** ![Paul\_Lutus](https://avatars.discourse-cdn.com/v4/letter/p/2bfe46/32.png) [@Paul\_Lutus](https://rubytalk.org/u/Paul_Lutus)\
**Post date:** [7 September 2006 01:50 UTC](https://rubytalk.org/t/multi-def-docs/30717/4 "2006-09-07T01:50:07Z")

</div>

YAD wrote:

> I thought Ruby allows you to define similar functions in parallel by  
> putting the parts that differ together in square brackets. Is there  
> some online documentation for that? I haven't been able to find it yet.

What follows is only approximately like what you are describing. Maybe it  
will give you some ideas:

#!/usr/bin/ruby

class Demo  
&nbsp;&nbsp;&nbsp;def initialize  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@op\_hash = {  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"+" =\> Proc.new { |y,x| y + x },  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"-" =\> Proc.new { |y,x| y - x },  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"\*" =\> Proc.new { |y,x| y \* x },  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"/" =\> Proc.new { |y,x| y / x }  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}  
&nbsp;&nbsp;&nbsp;end

&nbsp;&nbsp;&nbsp;def perform(y,x,m)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@op\_hash[m].call(y,x)  
&nbsp;&nbsp;&nbsp;end  
end

demo = Demo.new

puts demo.perform(1.0,3.0,"/")

Output: 0.333333333333333

> **···**
>
> --  
> Paul Lutus  
> [http://www.arachnoid.com](http://www.arachnoid.com)

---

<div class="post-metadata">

**Author:** ![YAD](https://avatars.discourse-cdn.com/v4/letter/y/df705f/32.png) [@YAD](https://rubytalk.org/u/YAD)\
**Post date:** [7 September 2006 17:00 UTC](https://rubytalk.org/t/multi-def-docs/30717/5 "2006-09-07T17:00:14Z")

</div>

Robert Klemme wrote:

> I have never heard of such a feature.

Sorry. Must be another language.

Eero Saynatkari wrote:  
\> If you mean something like this:  
\> some\_method(arg1, arg2[, arg3[, arg4]]) =\> nil  
\> It is just a documentation convention to indicate  
\> optional arguments.

No, it's something else.

Thanks for the help.

> **···**
>
> --  
> Yet another Dan
