Splat operator and Ruby instance variable assignments

@ubuntu:~$ irb --simple-prompt

class Foo
def initialize(x,y,z)
@x, @y, @z= x, y,z
end
def to_ary
[@x, @y, @z]
end
def to_hash
[@x => @y]
end
end
=> nil

foo = Foo.new(10,11,12)
=> #<Foo:0x00000001191738 @x=10, @y=11, @z=12>

My Question is with the below :

a,*b = foo
=> #<Foo:0x00000001191738 @x=10, @y=11, @z=12>

a
=> 10

b
=> [11, 12]

How or which internal method has been called to make such assignment to
a,*b from instance variables?

Thanks

On Mon, Feb 18, 2013 at 8:38 PM, Love U Ruby [email protected]
wrote:

end
=> 10

b
=> [11, 12]

How or which internal method has been called to make such assignment to
a,*b from instance variables?

set_trace_func lambda {|*x| p x}

and investigate yourself.

Cheers

robert

Now I have tried the below :

C:>irb --simple-prompt

class Foo
def initialize(x,y,z)
@x, @y, @z= x, y,z
end
def to_hash
[@x => @y]
end
end
=> nil

foo=Foo.new(10,11,12)
=> #<Foo:0x11f8968 @x=10, @y=11, @z=12>

a,*b=foo
=> #<Foo:0x11f8968 @x=10, @y=11, @z=12>

a
=> #<Foo:0x11f8968 @x=10, @y=11, @z=12>

b
=> []

Here the results are not same as with the above. So is it calling my
first instance method automatically? Couldn’t understand the logic.

Ok, understood what the guy wants …

“Love U Ruby” is a troll trying to steal time.
See his other “posts”.

If his original question would have been solely
about * then he would not have had the need to
write such awful code to pseudo-legitimize his
question.

I mean, he must know ruby because he purposely
returns an Array, and calls the method to_hash:

def to_hash
[@x => @y]
end

WTF?!?!

To the guy behind “Love U Ruby”, please - go grow
up, find a job, then you won’t have a need to go
trolling for reactions.

Marc H. wrote in post #1097736:

Ok, understood what the guy wants …

“Love U Ruby” is a troll trying to steal time.
See his other “posts”.

Really never thought about to “steal” your time, no intention of that. I
just asked you guys as you are expert. Just give me a tips or trick …
That’s enough, I will dig into that. Please don’t tell that way;You are
educated on this, thus asked. And another person also trying to be fit
on your domain, Is it bad? You should be proud by thinking that - what
you love,others too. If anyone incomplete, please try or at-least give
him/her something so that he can be strong.

We should share our knowledge - that’s why the forum built,to keep you
and like me, or you like you people come close and help each other.

I mean, he must know ruby because he purposely
returns an Array, and calls the method to_hash:

def to_hash
[@x => @y]
end

WTF?!?!

To the guy behind “Love U Ruby”, please - go grow
up, find a job, then you won’t have a need to go
trolling for reactions.

On Tue, Feb 19, 2013 at 3:46 PM, Love U Ruby [email protected]
wrote:

Marc H. wrote in post #1097736:

Ok, understood what the guy wants …

“Love U Ruby” is a troll trying to steal time.
See his other “posts”.

Really never thought about to “steal” your time, no intention of that. I
just asked you guys as you are expert. Just give me a tips or trick …

Then why do you not work with the replies you get?

We should share our knowledge - that’s why the forum built,to keep you
and like me, or you like you people come close and help each other.

Sharing is OK - spoonfeeding is not.

Cheers

robert

Love U Ruby wrote in post #1097729:

Now I have tried the below :

C:>irb --simple-prompt

class Foo
def initialize(x,y,z)
@x, @y, @z= x, y,z
end
def to_hash
[@x => @y]
end
end
=> nil

foo=Foo.new(10,11,12)
=> #<Foo:0x11f8968 @x=10, @y=11, @z=12>

a,*b=foo
=> #<Foo:0x11f8968 @x=10, @y=11, @z=12>

a
=> #<Foo:0x11f8968 @x=10, @y=11, @z=12>

b
=> []

Here the results are not same as with the above. So is it calling my
first instance method automatically? Couldn’t understand the logic.

WHY do you think that? why you dont get the IDEA that it MAYBE calls
to_ary? becaue *arg is the Splat Operator that parts Arrays into
members, and MAYBE it calls to_ary is the object is not an Array?

Ryan D. wrote in post #1097840:

On Feb 19, 2013, at 6:46, Love U Ruby [email protected] wrote:

Really never thought about to “steal” your time, no intention of that. I
just asked you guys as you are expert. Just give me a tips or trick …
That’s enough, I will dig into that. Please don’t tell that way;You are
educated on this, thus asked. And another person also trying to be fit
on your domain, Is it bad?

Yes, the way you do it IS bad. You are a help vampire:

http://slash7.com/2006/12/22/vampires/

As described below, you are a “leech” help vampire:

http://jasonwryan.com/blog/2012/03/17/vampires/

As I’ve said before, mend your ways.

It’s all about the perception… depends on people mentality. Forum is
to help someone. I would agree with Robert, although not with you. You
people have time to browse through these links but when someone would
ask something - you are saying “NOT TO WASTE YOUR TIME”. you know my
name… right? so any post with my name please ignore… Please don’t
spread such bad things over all. Remember you also passed such days when
you were junior to ruby…

Peter H. wrote in post #1097848:

On 19 February 2013 20:35, Love U Ruby [email protected] wrote:

Forum is to help someone.

Firstly this is not a forum but a mailing list.
Second we do not come here to help people, we come here because we are
members of a community. We help people because we feel like it not
because
we have a duty to.

You are right about one thing though, it is all about perception. Why do
you think people call you help vampire?

Leave it. Answering such cheap things seems to me really time wastage.
“And be remember - a just brown tree welcomes people who are giving
water at it’s root, but never disrespect who are not.”

people. It seems I am asking money from their accounts. I am asking to 
share their tips if any, but ........ have no words.

Thanks

On Feb 19, 2013, at 6:46, Love U Ruby [email protected] wrote:

Really never thought about to “steal” your time, no intention of that. I
just asked you guys as you are expert. Just give me a tips or trick …
That’s enough, I will dig into that. Please don’t tell that way;You are
educated on this, thus asked. And another person also trying to be fit
on your domain, Is it bad?

Yes, the way you do it IS bad. You are a help vampire:

http://slash7.com/2006/12/22/vampires/

As described below, you are a “leech” help vampire:

http://jasonwryan.com/blog/2012/03/17/vampires/

As I’ve said before, mend your ways.

On 19 February 2013 20:35, Love U Ruby [email protected] wrote:

Forum is to help someone.

Firstly this is not a forum but a mailing list.
Second we do not come here to help people, we come here because we are
members of a community. We help people because we feel like it not
because
we have a duty to.

You are right about one thing though, it is all about perception. Why do
you think people call you help vampire?

On 19 February 2013 21:22, Love U Ruby [email protected] wrote:

people. It seems I am asking money from their accounts. I am asking to
share their tips if any, but ........ have no words.


You are asking for their time which is a commodity that can never be got
back. If I spend money I can just earn some more, the time I spend here
is
lost when it passes.

I commute 5 hours a day, I work 8 hours a day, I sleep 7 hours a day. Do
the maths

Just replying to this post will take around 10 to 15 minutes as I stop,
rewrite, reedit, reread repeatedly.

Just because we give freely does not mean it is worthless and it is
certainly not cheap.

Peter H. wrote in post #1097851:

On 19 February 2013 21:22, Love U Ruby [email protected] wrote:

people. It seems I am asking money from their accounts. I am asking to
share their tips if any, but ........ have no words.


You are asking for their time which is a commodity that can never be got
back. If I spend money I can just earn some more, the time I spend here
is

These all are vague.

Then how should I call “Google” who keep sharing the knowledge to
everyone “FREE”, how would you consider “YouTube” who does the same job.

How would you consider the the man : “David A. Black” writer of “The
Well-Grounded Ruby”. Go to the link: and see how is he redelivering all
his speech what he already mentioned in his book and “YouTube” giving us
it FREE : http://www.youtube.com/watch?v=Xt6c6r4fbBs

So in simple sentence it is depends upon people mentality, who felt
disturbed when he shouldn’t but he can obviously. But in such a case
don’t need to be keep shouting. If you love to share knowledge share
it,otherwise keep quite. Don’t try to assemble a group of like you.

Its not about help,not about money, only about dedications… then you
don’t have. — Thanks

Always interesting when people bring out the proverbs

On Tue, Feb 19, 2013 at 1:22 PM, Love U Ruby [email protected]
wrote:

Leave it. Answering such cheap things seems to me really time wastage.
“And be remember - a just brown tree welcomes people who are giving
water at it’s root, but never disrespect who are not.”

Are you sure you grasp which role you are in the proverb at the moment?
The
next paragraph would seem to indicate otherwise…

people. It seems I am asking money from their accounts. I am asking to
share their tips if any, but ........ have no words.

Not very respectful of those not “giving water”.

Going back to your question - shocking what the words “splat ruby” might
bring someone as a first hit.

John

John W Higgins wrote in post #1097852:

Always interesting when people bring out the proverbs

On Tue, Feb 19, 2013 at 1:22 PM, Love U Ruby [email protected]
wrote:

people. It seems I am asking money from their accounts. I am asking to
share their tips if any, but ........ have no words.

Not very respectful of those not “giving water”.

Your catch is wrong, so I am helpless.

John

This whole exchange reminds of this quote:

I went to a bookstore and asked the saleswoman, “Where’s the self-help
section?” She said if she told me, it would defeat the purpose.

Anyway, consider this line of reasoning:

  1. Do not feed the trolls.
  2. Goto 1

On Tue, Feb 19, 2013 at 1:55 PM, Love U Ruby [email protected]
wrote:

Not very respectful of those not “giving water”.

Your catch is wrong, so I am helpless.

So you refuse to offer help and explain your great proverb to someone
who
might not understand the meaning of it? That surely wouldn’t take place
in
your utopian view of this area would it?

John

On Tue, Feb 19, 2013 at 1:52 PM, Love U Ruby [email protected]
wrote:

Its not about help,not about money, only about dedications… then you
don’t have. — Thanks

Proverb time again apparently…

John

On Tue, 19 Feb 2013 22:37:59 +0100, Peter H.
[email protected] wrote:

Just replying to this post will take around 10 to 15 minutes as I stop,
rewrite, reedit, reread repeatedly.

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

On Feb 19, 2013, at 12:35 , Love U Ruby [email protected] wrote:

to help someone. I would agree with Robert, although not with you.
It is about the perception of the group. Not the individual. The more
you behave the way you do, the more the group will perceive you as a
help vampire. Tho, after seeing the rest of your responses to this
thread, the more you come off like a troll. Keep up the good work.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs