Hi –
i was wondering if anyone’s thought any more on the idea of making arguments
actual objects in there own right.
i talked about this a bit before in relation to Arrays and Hashes.
i think it would be a powerful tool to be able to pass argument lists around.
for example:
def i_take_args(*args)
puts args.inspect
end
def i_give_args
return [1, 2, 3].to_arg
end
i_take_args(i_give_args) #—> [1,2,3] ( not [[1,2,3]] )
what does this really amount to? you see, this makes for a 100% OO way to do
what we normally do with *.
I don’t think there’s anything wrong with using * . We use operators
in Ruby all the time (like , . , (), etc.). Also, there are lots of
cases where you use * other than in argument lists. As long as it’s
there, it seems fine to use it for argument lists too.
There’s another conundrum here. How would you define to_arg? What
would its return value be? Let’s say you did:
class Array
def to_arg
*self
end
end
This will return an array. Since Ruby uses Arrays as its mechanism
for handling multiple return values, any method called on any object
that returns more than one value (including Array#to_arg) will return
an Array. That’s why you need an operator like * to manipulate arrays
directly.
i_take_args *[1,2,3] # this is a syntatical means (what would you call it?)
I know this is just an example, but don’t forget that you can pass a
literal list: i_take-args(1,2,3)
i_take_args [1,2,3].to_arg # the OO Way!!!
Oh, we can get more OO than that:
send(:i_take_args,Array.new.push(1,2,3).to_arg)

David
···
On Mon, 13 Jan 2003, Tom Sawyer wrote:
–
David Alan Black
home: dblack@candle.superlink.net
work: blackdav@shu.edu
Web: http://pirate.shu.edu/~blackdav