The meanings of Asterisk (and Webby)

L

Leslie Viljoen

Hi all!

I have a class that is used in a Webby page. The class needs to make
use of a function within three modules:

--------------------------------------------
module Webby
module Helpers #:nodoc:
module UrlHelper
--------------------------------------------

Since the function is an "instance"
function, I need to include the modules like so:

--------------------------------------------
class Categoriser
include Webby::Helpers::UrlHelper
--------------------------------------------

Later in my class I have (bear with me):

--------------------------------------------
def render
..
html << %[<li> #{link_to_page:)title => r.title)} </li>]
--------------------------------------------

link_to_page (within the three modules) looks like this:

--------------------------------------------
def link_to_page( *args )
self.link_to(*_find_page(args))
end
--------------------------------------------

And gives me:
NoMethodError Exception: undefined method `find' for nil:NilClass

I can't find any reference to this usage of the asterisk, and
I don't know what the *_find_page does. Can anyone explain it to me?


Les
 
J

Jano Svitok

Hi all!

I have a class that is used in a Webby page. The class needs to make
use of a function within three modules:

--------------------------------------------
module Webby
module Helpers #:nodoc:
module UrlHelper
--------------------------------------------

Since the function is an "instance"
function, I need to include the modules like so:

--------------------------------------------
class Categoriser
include Webby::Helpers::UrlHelper
--------------------------------------------

Later in my class I have (bear with me):

--------------------------------------------
def render
..
html << %[<li> #{link_to_page:)title => r.title)} </li>]
--------------------------------------------

link_to_page (within the three modules) looks like this:

--------------------------------------------
def link_to_page( *args )
self.link_to(*_find_page(args))
end
--------------------------------------------

And gives me:
NoMethodError Exception: undefined method `find' for nil:NilClass

I can't find any reference to this usage of the asterisk, and
I don't know what the *_find_page does. Can anyone explain it to me?

It's called the 'splat' operator.

see e.g.
http://theplana.wordpress.com/2007/03/03/ruby-idioms-the-splat-operator/
http://redhanded.hobix.com/bits/theSiphoningSplat.html
http://ola-bini.blogspot.com/2006/11/nooks-and-crannies-of-ruby.html
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,571
Members
45,045
Latest member
DRCM

Latest Threads

Top