Multi-def docs?

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.

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.

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

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

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.