For instance, why does
print "my obj is #{[1]}"
produce
my obj is 1
rather than
my obj is [1]
?
It seems silly to have to type out inspect
each time, and it's error-prone besides.
print "print "my obj is #{[1].inspect}"
May I be so bold as to propose changing this
surprising behavior while Ruby is still young
and not tied to a mammoth legacy code base?
Issac
class Array
def to_s
self.inspect
end
end
Issac
In message "[ruby-talk:28388] The maddening output of Arrays"
on 01/12/13, Issac Trotts <ITr...@IdolMinds.com> writes:
|May I be so bold as to propose changing this
|surprising behavior while Ruby is still young
|and not tied to a mammoth legacy code base?
We are open to proposals.
But I have to say: Ruby has been out there for more than 6 years.
It's a long time for a software, isn't it? Ruby is older than Java.
Back to the original issue, recently I changed the Array#to_s behavior
(not in a way you proposed, but anyway), and it caused many problems
so that I restored old bahavior. So I guess this proposal might be
sort of hard one.
matz.
Maybe there should be something about the array
surprise on the FAQ. If there is, I missed it.
Issac
> -----Original Message-----
> From: ma...@ruby-lang.org [mailto:ma...@ruby-lang.org]
> Sent: Wednesday, December 12, 2001 11:56 PM
> To: ruby...@ruby-lang.org
> Wow, I didn't know Ruby had been around that long.
> I only heard about it this year.
It was a secret of the Japanese for a while.
I first heard of it in 1999. At that time, ruby-talk was
fewer than 20 messages a day if I remember right,
and there were not many American-sounding names
on the list (except Dave Thomas and Andy Hunt).
And actually Dave.kind_of? British #=> true
Hal
> But I have to say: Ruby has been out there for more than 6 years.
>
> matz.
yes, but. how many years has ruby had formal documentation in english?
how many years has java had formal docs in english?
joe, in english.
On Thu, 13 Dec 2001, Issac Trotts wrote:
> It's a good thing Ruby makes this so easy to fix:
>
> class Array
> def to_s
> self.inspect
> end
> end
The snag with that is that it doesn't propagate to #puts:
irb(main):019:0> class Array; def to_s; inspect; end; end
nil
irb(main):020:0> a = [1,2,3]
[1, 2, 3]
irb(main):021:0> print a
[1, 2, 3]nil # OK, what you want
irb(main):022:0> puts a
1 # Not what you want
2
3
nil
This is the thing that Matz mentioned he recently experimented with
changing but ended up deciding not to. It's specific to Array: that
is, #puts has special handling for Array and its subclasses. (I'm
still trying to come up with a way to change this that Matz will
accept :-)
David
--
David Alan Black
home: dbl...@candle.superlink.net
work: blac...@shu.edu
Web: http://pirate.shu.edu/~blackdav
Surely British is a module, not a class :-)
But hey, let's do this the Ruby Way:
dave.ancestors.include? British # => true
dave.respond_to? :lorry # => true
dave.respond_to? :crisps # => true
# Hmmm, so far so good.
dave.respond_to? :football # => true
dave.football == david.soccer # => true
In message "[ruby-talk:28409] Re: The maddening output of Arrays"
on 01/12/13, David Alan Black <dbl...@candle.superlink.net> writes:
|This is the thing that Matz mentioned he recently experimented with
|changing but ended up deciding not to. It's specific to Array: that
|is, #puts has special handling for Array and its subclasses. (I'm
|still trying to come up with a way to change this that Matz will
|accept :-)
I'm waiting. I'm waitin' ;-)
matz.
##
# print out Arrays Python-style
class Array
def to_s
self.inspect
end
end
##
# puts Arrays Python-style
alias oldputs puts
def puts(obj)
if obj.kind_of? Array
oldputs(obj.inspect)
else
oldputs(obj)
end
end
> -----Original Message-----
> From: David Alan Black [mailto:dbl...@candle.superlink.net]
> Sent: Thursday, December 13, 2001 6:11 AM
> To: ruby...@ruby-lang.org
> Subject: [ruby-talk:28409] Re: The maddening output of Arrays
>
>
> Hi --
>
> On Thu, 13 Dec 2001, Issac Trotts wrote:
>
> > It's a good thing Ruby makes this so easy to fix:
> >
> > class Array
> > def to_s
> > self.inspect
> > end
> > end
>
> The snag with that is that it doesn't propagate to #puts:
>
> irb(main):019:0> class Array; def to_s; inspect; end; end
> nil
> irb(main):020:0> a = [1,2,3]
> [1, 2, 3]
> irb(main):021:0> print a
> [1, 2, 3]nil # OK, what you want
> irb(main):022:0> puts a
> 1 # Not what you want
> 2
> 3
> nil
>
>
> This is the thing that Matz mentioned he recently experimented with
> changing but ended up deciding not to. It's specific to Array: that
> is, #puts has special handling for Array and its subclasses. (I'm
> still trying to come up with a way to change this that Matz will
> accept :-)
>
>
In message "[ruby-talk:28991] Re: The maddening output of Arrays"
on 01/12/20, Joseph Benik <jobe...@hotmail.com> writes:
|> But I have to say: Ruby has been out there for more than 6 years.
|yes, but. how many years has ruby had formal documentation in english?
Formal? None. ;-)
But I have to be slow to change not to crash millions of lines of Ruby
code.
matz.