Combine array(string) to string?

str= “ABCDE”
arr = Array.new

arr = text.split “”

and how can I cambine array ‘arr’ into string again??

On Thursday 20 March 2008, Pat K. wrote:

str= “ABCDE”
arr = Array.new

arr = text.split “”

and how can I cambine array ‘arr’ into string again??

arr.join ‘’

Stefano

On Thu, Mar 20, 2008 at 4:44 AM, Pat K.
[email protected] wrote:

str= “ABCDE”
arr = Array.new

You really don’t need to declare your type. The arr = Array.new
statement is unnecessary.

arr = text.split “”

I’m not sure, but I think you meant arr = str.split “”

and how can I cambine array ‘arr’ into string again??

If the global $, is okay, you can just do arr.join, but if you can’t
be sure, then arr.join “”

Todd

On 3/20/08, Todd B. [email protected] wrote:

On Thu, Mar 20, 2008 at 4:44 AM, Pat K. [email protected] wrote:

str= “ABCDE”
arr = Array.new

You really don’t need to declare your type. The arr = Array.new
statement is unnecessary.

In fact, there’s no way to declare types of variables in Ruby.

At any given time a variable is bound to a particular object, but
which object (with its ‘type’, whatever that means) can change by
reassignment to the variable.

Somehow, it seems that this notion of ‘declaring’ a variable type by
assigning a ‘prototype’ object before setting the variable to the
‘real’ value seems to have become a common misconception in several
threads here on ruby-talk. Not sure why.


Rick DeNatale

My blog on Ruby
http://talklikeaduck.denhaven2.com/

On 20.03.2008 11:49, Todd B. wrote:

On Thu, Mar 20, 2008 at 4:44 AM, Pat K. [email protected] wrote:

str= “ABCDE”
arr = Array.new

You really don’t need to declare your type. The arr = Array.new
statement is unnecessary.

Sorry to be nitpicky, this is in no way a type declaration. It is just
a superfluous object creation and assignment.

Kind regards

robert

If the global $, is okay, you can just do arr.join, but if you can’t
be sure, then arr.join “”

There is no need to use the empty string as parameter it is the
default, OP should however know that split and join do not have the
same default parameters

space = " "
empty = “”
split is the same as split( space )
and
join is the same as join( empty )
:frowning:
Cheers
Robert


http://ruby-smalltalk.blogspot.com/


Whereof one cannot speak, thereof one must be silent.
Ludwig Wittgenstein

On Thu, Mar 20, 2008 at 12:29 PM, Robert K.
[email protected] wrote:

On 20.03.2008 11:49, Todd B. wrote:

On Thu, Mar 20, 2008 at 4:44 AM, Pat K. [email protected] wrote:

str= “ABCDE”
arr = Array.new

You really don’t need to declare your type. The arr = Array.new
statement is unnecessary.

Sorry to be nitpicky, this is in no way a type declaration. It is just
a superfluous object creation and assignment.

Okay, “the instantiation of the Array object is unnecessary”. From
some newbies, I’ve seen them pull this type of code practice from
fortran, pascal, c, etc… so I used the phrase “declare your type”.

Kind regards

    robert

Todd

On 20.03.2008 21:48, Todd B. wrote:

Sorry to be nitpicky, this is in no way a type declaration. It is just
a superfluous object creation and assignment.

Okay, “the instantiation of the Array object is unnecessary”. From
some newbies, I’ve seen them pull this type of code practice from
fortran, pascal, c, etc… so I used the phrase “declare your type”.

I can see where that comes from and I did not want to disregard the
point you were trying to make. I just thought it a bit unfortunate that
your wording kind of encourages the practice by insinuating that there
is indeed something like a variable type declaration in Ruby. :slight_smile:

Cheers

robert

On Fri, Mar 21, 2008 at 3:39 AM, Robert K.
[email protected] wrote:

    robert

Ahh, I see. After reading my post again, I realize it wasn’t that
clear. I was trying to cut down static practice.

There exists, however, typing in Ruby; it’s just not temporally
static. It’s interesting, I’ve even noticed people use the word
“type” to describe a prototype (class) on this list.

Todd

On Mar 20, 6:09 am, Robert D. [email protected] wrote:

If the global $, is okay, you can just do arr.join, but if you can’t
be sure, then arr.join “”

There is no need to use the empty string as parameter it is the
default,

No, $, is the default.

irb(main):001:0> [3,4].join
=> “34”
irb(main):002:0> $, = ‘-’
=> “-”
irb(main):003:0> [3,4].join
=> “3-4”

On 22.03.2008 03:45, Todd B. wrote:

On Fri, Mar 21, 2008 at 3:39 AM, Robert K.
[email protected] wrote:

On Thu, Mar 20, 2008 at 12:29 PM, Robert K.
[email protected] wrote:
I can see where that comes from and I did not want to disregard the
point you were trying to make. I just thought it a bit unfortunate that
your wording kind of encourages the practice by insinuating that there
is indeed something like a variable type declaration in Ruby. :slight_smile:

Ahh, I see. After reading my post again, I realize it wasn’t that
clear. I was trying to cut down static practice.

Absolutely agree.

There exists, however, typing in Ruby; it’s just not temporally
static.

Yes, that’s true. I would have to think hard to find a typeless
programming language. Can’t remember any one - and it probably would
not be useful anyway: if there is not at least a single type there are
no values. And without values there is no state to manipulate… :slight_smile:

It’s interesting, I’ve even noticed people use the word
“type” to describe a prototype (class) on this list.

Yeah, the subtleties of all types of type related terms in CS. :slight_smile:

Kind regards

robert

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