From: James Edward Gray II Date: 2005-12-13T08:58:18+09:00 Subject: Re: Way to combing Hash Definition sans => with %w() ? On Dec 12, 2005, at 5:41 PM, Dan Diebolt wrote: >> Hash[*%w(apple bananna orange grape)] > > Thanks but what exactly is the asterisk doing (what's the receiver)? That asterisk is Ruby "splat" or "explode" operator, in this context. The receiver is the Array, which is expanded back out into its individual elements (can only be used as the final parameter in a method call). It also works in reverse as the "slurp" operator: def my_method( arg1, arg2, *arr_of_all_leftover_args ) In this case, it slurps the passed args into an Array. Again it must be the final parameter (except for a block). >> def show( one, two, three ) >> p one >> p two >> p three >> end => nil >> arr = (1..3).to_a => [1, 2, 3] >> show(*arr) 1 2 3 => nil >> def slurp( *args ) >> p args >> end => nil >> slurp(1, 2, 3) [1, 2, 3] => nil Hope that helps. James Edward Gray II