Forum: Ruby with or without arguments - how?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
A74096209c78118ff69d50a51129d697?d=identicon&s=25 Jason Lillywhite (jlillywh)
on 2009-01-24 07:03
I've used methods before that work with or without arguments. I've tried
to figure it out but can't get to the bottom of it. Could someone give
me a hint how you would go about creating a method that works for either
of these cases?

mymethod(x, y)
  x + y
end

Then somehow get this to work without the (x, y) arguments...? What I
want is to have a method that can do something on default if no
arguments are spec'd or I can refine what it does by adding arguments.
017e05d1a49ffa59ea03e149e7af720b?d=identicon&s=25 Chris Shea (chrisshea)
on 2009-01-24 07:20
(Received via mailing list)
On Jan 23, 11:01 pm, Jason Lillywhite <jason.lillywh...@gmail.com>
wrote:
> want is to have a method that can do something on default if no
> arguments are spec'd or I can refine what it does by adding arguments.
> --
> Posted viahttp://www.ruby-forum.com/.

What methods? Have you looked at the source for those methods? Have
you read Programming Ruby? What about this section (http://www.ruby-
doc.org/docs/ProgrammingRuby/html/tut_methods.html)?

HTH,
Chris
C1138881c3c40b21e9415a3c1fdd3a0b?d=identicon&s=25 Victor Goff (kotp)
on 2009-01-24 07:21
(Received via mailing list)
Try this:
my_method(x = 1, y = 1)
  x + y
end

Warmest Regards,

Victor H. Goff III


On Fri, Jan 23, 2009 at 11:01 PM, Jason Lillywhite <
A74096209c78118ff69d50a51129d697?d=identicon&s=25 Jason Lillywhite (jlillywh)
on 2009-01-24 07:24
OK, sorry this was a dumb question. I missed default values.

Thank you.
E0d864d9677f3c1482a20152b7cac0e2?d=identicon&s=25 Robert Klemme (Guest)
on 2009-01-24 17:41
(Received via mailing list)
On 24.01.2009 07:22, Jason Lillywhite wrote:
> OK, sorry this was a dumb question. I missed default values.

... and probably the splash operator as well which can be used to
similar purpose.

Kind regards

  robert
This topic is locked and can not be replied to.