argument hash

C

Charles Mills

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
 
C

Charles Mills

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
 
R

Robert Klemme

Charles Mills said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,785
Messages
2,569,624
Members
45,318
Latest member
LuisWestma

Latest Threads

Top