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
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
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/\.
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
--
Paul Lutus
http://www.arachnoid.com
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