Take the 2-minute tour ×

I'm trying to learn both Ruby and Rails and I'm looking at Michael Hartl's RailsTutorial.org. In Chapter 7 or 8, he's working on sessions and I think he's using a method call as an argument to a function, but I'm not totally sure of it. It's not something I've seen before.

Please have a look at the first function in the "private" section below where the argument is remember_token. does this mean that the return value of the function remember_token becomes the argument(s) for User.authenticate_with_salt?

def current_user
    @current_user ||= user_from_remember_token

  def signed_in?


    def user_from_remember_token

    def remember_token
      cookies.signed[:remember_token] || [nil, nil]
share|improve this question
Perhaps obvious, but what makes this so weird-looking is not the splat operator but rather that nothing indicates that remember_token is a method. In most other languages, you need to do remember_token() or something to differentiate method from variable. –  Yar Nov 25 '11 at 3:42
add comment

2 Answers

up vote 1 down vote accepted


It's also "splatted" (the *), meaning the return value (the cookie bits, or the [nil, nil] array if there's no cookie) is unpacked from the array, and sent as two individual parameters (roughly) to User.authenticate_with_salt.

share|improve this answer
add comment

As @DaveNewton mentioned the ruby's "splat" operator is being used.

There's a lot you can do with splat so here's a blog with some great examples.

One thing to keep in mind is that splat can be used both while defining a method and also when calling a method.

# when defining a method
def my_method(name, age, *everything_else)

# when calling a method
some_info = other_method(*stuff)
share|improve this answer
add comment

Your Answer


