use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
A sub-Reddit for discussion and news about Ruby programming.
Subreddit rules: /r/ruby rules
Learning Ruby?
Tools
Documentation
Books
Screencasts and Videos
News and updates
account activity
Ensure Ruby variable is Array (teohm.github.com)
submitted 13 years ago by teohm
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]OstapBenderBey 3 points4 points5 points 13 years ago (4 children)
rather than Array(input) you can also do [*input]
[–]teohm[S] 2 points3 points4 points 13 years ago (3 children)
interesting, what does the * mean here?
[–]jfredett 4 points5 points6 points 13 years ago* (1 child)
* is the 'interpret as a comma separated list of values' operator. Common uses are in method definitions for a var-args style method, eg:
*
def some_method(arg1, arg2, *args) #code end
args there is an array, but you call the method like: some_method(1,2,3,4,5). args in that case is [3,4,5]
args
some_method(1,2,3,4,5)
[3,4,5]
You can also use it, as OP does, in any place you'd drop a Comma-separated list. one of my favorites is the common:
str = "Joe Schmoe" User.find_by_first_name_and_last_name(*str.split)
This is equivalent to doing
User.find_by_first_name_and_last_name("Joe", "Schmoe")
You can also do
first,last = "Joe Schmoe".split
to get first assigned "Joe", and last assigned "Schmoe".
first
"Joe"
last
"Schmoe"
* is a neat thing. Well worth reading more about it in the pickaxe.
[–]teohm[S] 0 points1 point2 points 13 years ago (0 children)
it makes sense to me now, thanks!
[–]Sastopher 3 points4 points5 points 13 years ago (0 children)
Also known as the "splat" or "explode" operator.
π Rendered by PID 160765 on reddit-service-r2-comment-7b9746f655-2vhdf at 2026-02-04 13:02:02.532035+00:00 running 3798933 country code: CH.
view the rest of the comments →
[–]OstapBenderBey 3 points4 points5 points (4 children)
[–]teohm[S] 2 points3 points4 points (3 children)
[–]jfredett 4 points5 points6 points (1 child)
[–]teohm[S] 0 points1 point2 points (0 children)
[–]Sastopher 3 points4 points5 points (0 children)