Combine array(string) to string?

str= "ABCDE"
arr = Array.new

arr = text.split ""

and how can I cambine array 'arr' into string again??

···

--
Posted via http://www.ruby-forum.com/.

arr.join ''

Stefano

···

On Thursday 20 March 2008, Pat Kiatchaipipat wrote:

str= "ABCDE"
arr = Array.new

arr = text.split ""

and how can I cambine array 'arr' into string again??

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 Thu, Mar 20, 2008 at 4:44 AM, Pat Kiatchaipipat <hb.pat87@hotmail.com> wrote:

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.

···

On 3/20/08, Todd Benson <caduceass@gmail.com> wrote:

On Thu, Mar 20, 2008 at 4:44 AM, Pat Kiatchaipipat <hb.pat87@hotmail.com> wrote:
> str= "ABCDE"
> arr = Array.new

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

--
Rick DeNatale

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

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

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

Kind regards

  robert

···

On 20.03.2008 11:49, Todd Benson wrote:

On Thu, Mar 20, 2008 at 4:44 AM, Pat Kiatchaipipat <hb.pat87@hotmail.com> wrote:

str= "ABCDE"
arr = Array.new

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

>> 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 Thu, Mar 20, 2008 at 12:29 PM, Robert Klemme <shortcutter@googlemail.com> wrote:

On 20.03.2008 11:49, Todd Benson wrote:
> On Thu, Mar 20, 2008 at 4:44 AM, Pat Kiatchaipipat <hb.pat87@hotmail.com> wrote:

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 Mar 20, 6:09 am, Robert Dober <robert.do...@gmail.com> 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,

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 20.03.2008 21:48, Todd Benson wrote:

On Thu, Mar 20, 2008 at 12:29 PM, Robert Klemme > <shortcutter@googlemail.com> wrote:

On 20.03.2008 11:49, Todd Benson wrote:
> On Thu, Mar 20, 2008 at 4:44 AM, Pat Kiatchaipipat <hb.pat87@hotmail.com> 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".

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 Fri, Mar 21, 2008 at 3:39 AM, Robert Klemme <shortcutter@googlemail.com> wrote:

> On Thu, Mar 20, 2008 at 12:29 PM, Robert Klemme > > <shortcutter@googlemail.com> 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:

Cheers

        robert

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

···

On 22.03.2008 03:45, Todd Benson wrote:

On Fri, Mar 21, 2008 at 3:39 AM, Robert Klemme > <shortcutter@googlemail.com> wrote:

> On Thu, Mar 20, 2008 at 12:29 PM, Robert Klemme >> > <shortcutter@googlemail.com> wrote: