Splat operator and Ruby instance variable assignments

On 19 February 2013 22:34, Bartosz Dziewoński [email protected]
wrote:

You could also finally shut up, as it wastes the time of every list
subscriber to scan and delete your messages every day.

Well you could always put my email address in the kill file for your
news
reader or if you use Gmail you could create a filter to delete all posts
from my email address. Then you would never have to ever see them. I’m
sure
that such facilities exist in most software (unless you are reading this
on
a forum, in which case you will have to find out for yourself). If my
posts
were causing you such grief then surely you would have done this
already.

But then you would miss out on me giving you this useful advice :slight_smile:

when we write the “range” with splat(*) generally got the array as
below:

a = *(2…5)
=> [2, 3, 4, 5]

But in the previous case why I got [2, 3, 4, 5] not [[2, 3, 4, 5]]

a = [*(2…5)]
=> [2, 3, 4, 5]

here and there concept in Ruby… Huuhh :wink:

hi all
i am a follower
i admire the great efforts
finding solutions in Ruby
we can watch experts unravel them here

turning to others for help may lead to misunderstandings
mentors freely maintain a valuable driving force in the forum
this is a great forum for precise advice that makes a real difference

i am a slow learner i study by repetition as if i am a bit thick in the
head
clearly wrath awaits aspirants who crib or skip any staple rules of Ruby
spotting mistakes helps strive to learn more effectively

much obliged to everyone and best wishes for all through the year

timo

On Wed, Feb 20, 2013 at 8:27 PM, Peter H. <

On 25 February 2013 02:24, Love U Ruby [email protected] wrote:

here and there concept in Ruby… Huuhh :wink:

This is a legitimate question.

As we’ve seen, on the splitting side (i.e. the RHS of an assignment, if
any) the splat operator attempts to convert an object into an array,
pretty
sure it does it by calling that object’s to_a method. Thus the
following
would be functionally identical:

a = *(2…5)
a = (2…5).to_a

However it does more than that. The splitting side of splat can splice
the
splatted value into an array, for example:

a = [1, *(2…3), 4] # => a = [1,2,3,4]

By paring that down and removing the 1 and 4, you can see why:

a = [ *(2…3) ] # => a = [2,3]

It splices the splatted range into the existing (anonymous) array. If
you
want it to be nested inside, you have to explicitly call (2..3).to_a
instead.