ruby-1.9.2-head > ary.object_id
=> 87171620
ruby-1.9.2-head > default = [*ary]
ruby-1.9.2-head > default.object_id
=> 87171620
Is that a bug or a feature ? I would expect such construction to create
a new array.
Robert Pankowecki
···
--
Posted via http://www.ruby-forum.com/ .
botp1
(botp)
29 October 2010 15:57
2
if a.is_a? Array
(b=[*a]) == (b=*a)
#=> true
(b=*a) == (b=a)
#=> true
so
(b=[*a]) == (b=a)
#=> true
best regards -botp
···
On Fri, Oct 29, 2010 at 11:08 PM, Robert Pankowecki <robert.pankowecki@gmail.com> wrote:
ruby-1.9.2-head > ary.object_id
=> 87171620
ruby-1.9.2-head > default = [*ary]
ruby-1.9.2-head > default.object_id
=> 87171620
Thank you for the explanation. Now I understand the "why" and "how"
···
--
Posted via http://www.ruby-forum.com/ .
What's your point ?
I know that [*a] == a when a.is_?(Array). It's logical.
What I am saying is that in my opinion it should be a different array
instance with same elements.
a = [1]
b = [1]
a == b => true
but
a.object_id == b.object_id => false.
When you see such code:
[*a]
do you think a new array will be created ?
Because I do.
So I expect that for Array
[*a].object_id == a.object_id => false
Unless there is something that I am missing.
Robert Pankowecki
···
--
Posted via http://www.ruby-forum.com/ .
Ammar_Ali
(Ammar Ali)
29 October 2010 18:01
5
From Read Ruby: When given an object that does not respond to :to_a,
Kernel.Array() returns an Array with that object as its sole element.
Therefore, splatting such an object causes it to expand to itself,
effectively a no‐op.
Here' the link to the splat coverage: http://ruby.runpaint.org/variables#splat
HTH,
Ammar
···
On Fri, Oct 29, 2010 at 7:29 PM, Robert Pankowecki <robert.pankowecki@gmail.com> wrote:
What's your point ?
I know that [*a] == a when a.is_?(Array). It's logical.
What I am saying is that in my opinion it should be a different array
instance with same elements.
a = [1]
b = [1]
a == b => true
but
a.object_id == b.object_id => false.
When you see such code:
[*a]
do you think a new array will be created ?
Because I do.
So I expect that for Array
[*a].object_id == a.object_id => false
Unless there is something that I am missing.
botp1
(botp)
30 October 2010 03:30
6
What's your point ?
I know that [*a] == a when a.is_?(Array). It's logical.
of course LOL. forgot to affix the object_id.. i should have pasted
your code but was getting lazy that night...
so..
a=
=>
(b=[*a]).object_id == (b=*a).object_id
=> true
wc means, the is ignored
(b=*a).object_id == (b=a).object_id
=> true
so is *
(b=[*a]).object_id == (b=a).object_id
=> true
so is [* ]
When you see such code:
[*a]
do you think a new array will be created ?
Because I do.
the confusion is understandable. suffice it to say that the splat
cannot override literals or hell breaks loose
(b=[* ]).object_id == (b=* ).object_id
=> false
and splat does not even have a corresponding alias or method
lesson is: do not compare splatted objects.. it's undocumented and
very confusing :))
best regards -botp
···
On Sat, Oct 30, 2010 at 1:29 AM, Robert Pankowecki <robert.pankowecki@gmail.com> wrote: