Hi Robert,

At present I'm using the approach I mentioned before, but let me try and 
explain my confusion...

Every other language I've worked in, C, Perl, Python, Java...the way you 
call a function with arguments is: func(arg1, arg2, arg3). In Python you 
can have variable args and keyword args specified as (*args, **kwargs), 
but in general you define the arguments that a function expects, and 
then pass those arguments between parentheses. So the idea that I could 
do:

func(arg1,arg2,arg3) { block }

And a) Not get a syntax error, and b) Be able to define the parameters 
for the function as:

def func(*args)
yield
end

and not only get the args specified between the parens in *args, but 
also still pass the block and "yield" it, is a very new, and foreign, 
concept for me.

What I find a bit confusing about Ruby is that, given:

def func(*args)
args.each { |a| puts a }
yield
end

Then do the following:

>> func "this", "is", "a", "test", return_value("something")
this
is
a
test
This is the returning value: something
LocalJumpError: no block given
        from (irb):108:in `func'
        from (irb):110

This one is sort-of obvious since the function return_value (which is 
just a dummy function that simply shows calling a function with some 
arbitrary value and returning it slightly modified...so don't get hung 
up on it) is evaluated prior to being passed as an argument to func. But 
since there's no block, I get the LocalJumpError.

>> func "this", "is", "a", "test", { return_value("something") }
SyntaxError: compile error
(irb):111: odd number list for Hash
        from (irb):111

This is is also somewhat obvious because it isn't treating the {} as 
defining a block but attempting to define a hash...That's because I 
haven't "formally" defined the arguments, so the interpreter assumes 
everything is supposed to be an argument and not a block.

>> func("this", "is", "a", "test") { return_value("something") }
this
is
a
test
=> "This is the returning value: something"

This is still the odd one for me that now (sort-of) makes sense but 
would NOT be allowed in any language I've used in the past. So it's 
going to take some getting used to...

Rob

-- 
Posted via http://www.ruby-forum.com/.