[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

with or without arguments - how?

Jason

1/24/2009 6:01:00 AM

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.
--
Posted via http://www.ruby-....

4 Answers

Chris Shea

1/24/2009 6:15:00 AM

0

On Jan 23, 11:01 pm, Jason Lillywhite <jason.lillywh...@gmail.com>
wrote:
> 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.
> --
> Posted viahttp:/.......

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

HTH,
Chris

Victor H. Goff III

1/24/2009 6:19:00 AM

0

[Note: parts of this message were removed to make it a legal post.]

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 <
jason.lillywhite@gmail.com> wrote:

> 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.
> --
> Posted via http://www.ruby-....
>
>

Jason

1/24/2009 6:23:00 AM

0

OK, sorry this was a dumb question. I missed default values.

Thank you.
--
Posted via http://www.ruby-....

Robert Klemme

1/24/2009 4:37:00 PM

0

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

--
remember.guy do |as, often| as.you_can - without end