# Multi-def docs?

**URL:** <https://www.ruby-forum.com/t/multi-def-docs/67779>\
**Category:** Ruby\
**Created:** [September 6, 2006, 7:36pm UTC](https://www.ruby-forum.com/t/multi-def-docs/67779 "2006-09-06T19:36:40Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![YAD](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/df705f/32.png) [@YAD](https://www.ruby-forum.com/u/YAD)\
**Post date:** [September 6, 2006, 7:36pm UTC](https://www.ruby-forum.com/t/multi-def-docs/67779/1 "2006-09-06T19:36:40Z")

</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.

---

<div class="post-metadata">

**Author:** ![YAD](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/df705f/32.png) [@YAD](https://www.ruby-forum.com/u/YAD)\
**Post date:** [September 6, 2006, 8:57pm UTC](https://www.ruby-forum.com/t/multi-def-docs/67779/2 "2006-09-06T20:57:39Z")

</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.

---

<div class="post-metadata">

**Author:** ![YAD](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/df705f/32.png) [@YAD](https://www.ruby-forum.com/u/YAD)\
**Post date:** [September 6, 2006, 11:01pm UTC](https://www.ruby-forum.com/t/multi-def-docs/67779/3 "2006-09-06T23:01:05Z")

</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

```
robert
```

---

<div class="post-metadata">

**Author:** ![YAD](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/df705f/32.png) [@YAD](https://www.ruby-forum.com/u/YAD)\
**Post date:** [September 7, 2006, 3:51am UTC](https://www.ruby-forum.com/t/multi-def-docs/67779/4 "2006-09-07T03:51:30Z")

</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  
def initialize  
@op\_hash = {  
“+” =\> Proc.new { |y,x| y + x },  
“-” =\> Proc.new { |y,x| y - x },  
“\*” =\> Proc.new { |y,x| y \* x },  
“/” =\> Proc.new { |y,x| y / x }  
}  
end

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

demo = Demo.new

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

Output: 0.333333333333333

---

<div class="post-metadata">

**Author:** ![YAD](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/df705f/32.png) [@YAD](https://www.ruby-forum.com/u/YAD)\
**Post date:** [September 7, 2006, 7:01pm UTC](https://www.ruby-forum.com/t/multi-def-docs/67779/5 "2006-09-07T19:01:36Z")

</div>

Robert K. wrote:

> I have never heard of such a feature.  
> Sorry. Must be another language.

Eero S. 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.
