Hi,
Am Dienstag, 21. Jul 2009, 23:39:38 +0900 schrieb William Djingga:
$:.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
what does *%w mean in the line above?
An array expands to an argument list.
%w() is just an array:
%w[foo bar baz] == [ "foo", "bar", "baz"]
Here is an example for an *argument list.
def f a, b, *args
puts args.inspect
end
f( :x, :y, "i", "j")
# Output:
# ["i", "j"]
ary = ["foo", "bar"]
f( :x, :y, *ary)
# Output:
# ["foo", "bar"]
So the call will expand to
$:.unshift File.join(File.dirname(__FILE__), "..", "lib")
These will work as well:
ary = %w(a b c)
[ "foo", "bar", *ary] #=> ["foo", "bar", "a", "b", "c"]
case somestr
when *ary then do_sth
when *%w(quit exit bye) then break
end
Bertram