[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

argument hash

Charles Mills

10/20/2004 4:42:00 PM

After reading the "Too many default argument values!" thread I was
wondering why the following isn't possible:
##
def do_something(arg1, opt1, arg2, opt2)
# ...
end

my_meth("hey", :yada => "blue", :foo => "bar", "my_spreadsheet.xls", :wkst => "sheet1", :range =>
"A1:C5")

## END

Just wondering why the above call causes a syntax error instead of
having the same behavior as:
my_meth("hey", {:yada => "blue", :foo => "bar"}, "my_spreadsheet.xls",
{:wkst => "sheet1", :range => "A1:C5"})

Probably too ambiguous to parse effectively. (I get the feeling this
has already been asked on ruby talk.)

-Charlie



2 Answers

Charles Mills

10/20/2004 5:23:00 PM

0

I intended to write:

After reading the "Too many default argument values!" thread I was
wondering why the following isn't possible:
##
def my_meth(arg1, opt1, arg2, opt2)
# ...
end

my_meth("hey", :yada => "blue", :foo => "bar", "my_spreadsheet.xls", :wkst => "sheet1", :range =>
"A1:C5")

## END

Just wondering why the above call causes a syntax error instead of
having the same behavior as:
my_meth("hey", {:yada => "blue", :foo => "bar"}, "my_spreadsheet.xls",
{:wkst => "sheet1", :range => "A1:C5"})

Probably too ambiguous to parse effectively. (I get the feeling this
has already been asked on ruby talk.)

-Charlie




Robert Klemme

10/21/2004 7:48:00 AM

0


"Charles Mills" <cmills@freeshell.org> schrieb im Newsbeitrag
news:BE182BA4-22BC-11D9-8B98-000A95A27A10@freeshell.org...
> I intended to write:
>
> After reading the "Too many default argument values!" thread I was
> wondering why the following isn't possible:
> ##
> def my_meth(arg1, opt1, arg2, opt2)
> # ...
> end
>
> my_meth("hey", :yada => "blue", :foo => "bar", > "my_spreadsheet.xls", :wkst => "sheet1", :range =>
> "A1:C5")
>
> ## END
>
> Just wondering why the above call causes a syntax error instead of
> having the same behavior as:
> my_meth("hey", {:yada => "blue", :foo => "bar"}, "my_spreadsheet.xls",
> {:wkst => "sheet1", :range => "A1:C5"})
>
> Probably too ambiguous to parse effectively.

I think that's it. Optional arguments can only be at the end. Other than
that is simply undecidable which arg values belong to which arg.

robert