[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

The meanings of Asterisk (and Webby

Leslie Viljoen

2/18/2008 8:46:00 PM

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

2 Answers

Jano Svitok

2/18/2008 9:05:00 PM

0

On Feb 18, 2008 9:46 PM, Leslie Viljoen <leslieviljoen@gmail.com> wrote:
> 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...
http://redhanded.hobix.com/bits/theSiphoning...
http://ola-bini.blogspot.com/2006/11/nooks-and-crannies-of...

Leslie Viljoen

2/19/2008 8:44:00 AM

0

Thanks! I now know splats!