in reply to Re^2: Your named arguments
in thread Your named arguments
Since I cannot do that, I have to do something like:def add_child( Hash options is optional, Tree *children ) # Subroutine body here end
I'd much rather have the subroutine signature do that for me. Perl6 will have this and I hope Ruby2.0 will, but we'll have to see.def add_child( *children ) options = children[0].is_a( 'Hash' ) ? children.shift : Hash.new; if children.any? { |node| !node.is_a( 'Tree' ) }: raise ArgumentError "Non-Tree argument found in add_child()" end # Resume regular processing here end
|
---|