ruby: what does the asterisk in “p *1..10” mean

It’s the splat operator. You’ll often see it used to split an array into parameters to a function. def my_function(param1, param2, param3) param1 + param2 + param3 end my_values = [2, 3, 5] my_function(*my_values) # returns 10 More commonly it is used to accept an arbitrary number of arguments def my_other_function(to_add, *other_args) other_args.map { |arg| … Read more

Only index needed: enumerate or (x)range?

I would use enumerate as it’s more generic – eg it will work on iterables and sequences, and the overhead for just returning a reference to an object isn’t that big a deal – while xrange(len(something)) although (to me) more easily readable as your intent – will break on objects with no support for len…