Splat Operator in Ruby

Posted on March 18, 2008. Filed under: Uncategorized |

* is called the splat operator in ruby .The first time you come across is for variable argument.that is exactly what you will be using it for.it should be used as the last argument.

name,*rest_of_address = address[]

would put the first argument to name and rest to the * argument…

THe other thing about it is it gives a copy of the variable not the reference….

what you can do with this on Struct and Hash is split it….using splat as an array and get it individual…

you can use even in the case statement..to check the equal to

and *array passed on to the other array will flatten it..


Make a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

  • March 2008
    M T W T F S S
    « Feb   Apr »
  • My Fav

Liked it here?
Why not try sites on the blogroll...

%d bloggers like this: