[#6363] Re: rescue clause affecting IO loop behavior — ts <decoux@...>

>>>>> "D" == David Alan Black <dblack@candle.superlink.net> writes:

17 messages 2000/11/14
[#6367] Re: rescue clause affecting IO loop behavior — David Alan Black <dblack@...> 2000/11/14

Hello again --

[#6582] best way to interleaf arrays? — David Alan Black <dblack@...>

Hello --

15 messages 2000/11/26

[#6646] RE: Array Intersect (&) question — Aleksi Niemel<aleksi.niemela@...>

Ross asked something about widely known and largely ignored language (on

23 messages 2000/11/29
[#6652] RE: Array Intersect (&) question — rpmohn@... (Ross Mohn) 2000/11/29

aleksi.niemela@cinnober.com (Aleksi Niemel) wrote in

[#6723] Re: Array Intersect (&) question — Mathieu Bouchard <matju@...> 2000/12/01

> >Use a hash. Here's code to do both and more. It assumes that

[#6656] printing/accessing arrays and hashes — raja@... (Raja S.)

I'm coming to Ruby with a Python & Common Lisp background.

24 messages 2000/11/30

[ruby-talk:6533] Re: Question about the behavior of write attributes in blocks

From: "Christoph Rippel" <chr@...>
Date: 2000-11-22 22:37:46 UTC
List: ruby-talk #6533
Thank you for explanation - the output of "x".inspect() is

>>"x"

which made me assume that Strings are implemented as singletons  (which
doesn't make much sense in the presence of a replace() method).

I was hoping to be able to write
***********
x =  [1,2,3]
x.each { |i|    i+= 1  }
p x
****************
which has the output

>>[1, 2, 3]

and not the ``expected''

>>[2, 3, 4]

I wouldn't mind to write some thing like

*******************
x =  [1,2,3]
x.each { |i|    i.add_to 1 }
p x
**********************

but there is no such method for Fixnum and the only way I can think about
writing such a method always involves the use of the ``=()''-operator -
which means I am effectively stuck. The String Class seems to be one of the
few build in classes sporting a replace() method so I can write

***********
class String
def add_to(n)
        replace((self.to_i+n).to_s)
end
end

x =  ["1","2","3"]
x.each { |i|    i.add_to 1 }
p x

**************

This gives me the indented output

>> ["2", "3", "4"]

This is only a stop-cap measure since I really want to manipulate Arrays (or
binary trees) of Fixnum or more general any Object.

Any thoughts?
        Christoph



In This Thread