From: David A. Black on
Hi --

On Sat, 19 Dec 2009, Tony Arcieri wrote:

> I would absolutely love if Array recursively performed #=== on its
> arguments. AFAICT Array#=== is practically identical to Array#==

It's an interesting idea but I wonder how useful it would be, compared
to having case equality be essentially == for Arrays. I just can't
imagine that many cases of, say:

case array
when [/abc/, Fixnum, "hi"]

etc. I guess it might occasionally be used for checking regex matches
on a bunch of strings at the same time:

case user_data
when [first_name_re, last_name_re, age_re, email_re]

or something -- but even in such a case, you'd probably want to do it
in such a way that you could isolate which one went wrong.

On the other hand, something like:

case user_data
when other_user_data

seems like a more likely comparison scenario.


David

--
David A. Black
Senior Developer, Cyrus Innovation Inc.
THE COMPLEAT RUBYIST, Ruby training with Black/Brown/McAnally!
January 22-23, Tampa, Florida
Info and registration at http://www.thecompleatrubyist.com

From: Rick DeNatale on
On Sat, Dec 19, 2009 at 6:13 AM, David A. Black <dblack(a)rubypal.com> wrote:
> Hi --
>
> On Sat, 19 Dec 2009, Tony Arcieri wrote:
>
>> I would absolutely love if Array recursively performed #=== on its
>> arguments.  AFAICT Array#=== is practically identical to Array#==
>
> It's an interesting idea but I wonder how useful it would be, compared
> to having case equality be essentially == for Arrays. I just can't
> imagine that many cases of, say:
>
>  case array
>  when [/abc/, Fixnum, "hi"]

My imagination runs instead to all the possibilities of breaking
existing code if such a change to a fundamental class were made.

I've been amazed by how subtly disruptive, seemingly simple changes
like the result of Array#to_s between Ruby 1.8 and 1.9 can be
http://talklikeaduck.denhaven2.com/2009/10/27/its-the-little-things

It would be better I think to have a new class which acted like an
Array and did recursive === for the seemingly rare cases where this is
needed. And I don't think that such a class need be part of the
standard library. That's the beauty of a language like Ruby,
programmers can extend it for themselves to fit THEIR purposes, which
often are different from MY purposes.

--
Rick DeNatale

Blog: http://talklikeaduck.denhaven2.com/
Twitter: http://twitter.com/RickDeNatale
WWR: http://www.workingwithrails.com/person/9021-rick-denatale
LinkedIn: http://www.linkedin.com/in/rickdenatale

From: Gary Wright on

On Dec 19, 2009, at 10:32 AM, Rick DeNatale wrote:
>
> I've been amazed by how subtly disruptive, seemingly simple changes
> like the result of Array#to_s between Ruby 1.8 and 1.9 can be
> http://talklikeaduck.denhaven2.com/2009/10/27/its-the-little-things

I still don't understand that particular change. The 1.8 semantics of Array#to_s were much more useful in my mind than the 1.9 semantics.


Gary Wright




From: Caleb Clausen on
On 12/19/09, Rick DeNatale <rick.denatale(a)gmail.com> wrote:
> I've been amazed by how subtly disruptive, seemingly simple changes
> like the result of Array#to_s between Ruby 1.8 and 1.9 can be
> http://talklikeaduck.denhaven2.com/2009/10/27/its-the-little-things

I added this to my tests for 1.9 porting. It at least makes the
Array#to_s problems readily apparent. Not intended as a permanent
measure.

if defined? ::RUBY_VERSION and ::RUBY_VERSION[/^\d+.\d+/].to_f>=1.9
class ::Array
alias to_s_without_semantics_changed_warning to_s

def to_s
warn "calling Array#to_s from #{caller.first}; semantics have changed"
to_s_without_semantics_changed_warning
end
end
end

From: Benoit Daloze on
[Note: parts of this message were removed to make it a legal post.]

2009/12/19 Gary Wright <gwtmp01(a)mac.com>

>
> On Dec 19, 2009, at 10:32 AM, Rick DeNatale wrote:
> >
> > I've been amazed by how subtly disruptive, seemingly simple changes
> > like the result of Array#to_s between Ruby 1.8 and 1.9 can be
> > http://talklikeaduck.denhaven2.com/2009/10/27/its-the-little-things
>
> I still don't understand that particular change. The 1.8 semantics of
> Array#to_s were much more useful in my mind than the 1.9 semantics.
>
>
> Gary Wright
>
>
>
>
>
I don't think so, it became quite a mess when you did:
Values: [1, :b, "cd"]
1.8: Values: 1bcd
1.9: Values: [1, :b, "cd"]
I think the second shows better it's an Array.

Clearly Array#to_s was a (useful) shortcut to Array#join.

But I think that wasn't a way to do what you wanted. #to_s is made to show
the result in a String, usually on screen. It's quite different than wanting
to join every element with the following, what is the sense of #join.