# How to write ! version of non ! method?

**URL:** <https://www.ruby-forum.com/t/how-to-write-version-of-non-method/81724>\
**Category:** Rails\
**Created:** [March 14, 2006, 3:47pm UTC](https://www.ruby-forum.com/t/how-to-write-version-of-non-method/81724 "2006-03-14T15:47:17Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![g0nzo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/3bc359/32.png) [@g0nzo](https://www.ruby-forum.com/u/g0nzo)\
**Post date:** [March 14, 2006, 3:47pm UTC](https://www.ruby-forum.com/t/how-to-write-version-of-non-method/81724/1 "2006-03-14T15:47:17Z")

</div>

Hi!

How to write i.e. array.join! based on array.join method?

---

<div class="post-metadata">

**Author:** ![g0nzo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/3bc359/32.png) [@g0nzo](https://www.ruby-forum.com/u/g0nzo)\
**Post date:** [March 14, 2006, 3:53pm UTC](https://www.ruby-forum.com/t/how-to-write-version-of-non-method/81724/2 "2006-03-14T15:53:25Z")

</div>

On 3/14/06, szymek [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hi!
> 
> How to write i.e. array.join! based on array.join method?

What could this possibly mean? You have an array and you want to  
store a string inside of it?

It would help if you could explain what you’re really trying to do.

– James

---

<div class="post-metadata">

**Author:** ![g0nzo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/3bc359/32.png) [@g0nzo](https://www.ruby-forum.com/u/g0nzo)\
**Post date:** [March 14, 2006, 4:05pm UTC](https://www.ruby-forum.com/t/how-to-write-version-of-non-method/81724/3 "2006-03-14T16:05:50Z")

</div>

Hi –

On Tue, 14 Mar 2006, szymek wrote:

> Hi!
> 
> How to write i.e. array.join! based on array.join method?

array = []  
def array.join!(sep=$,)  
join(sep)  
end

But I doubt that’s what you mean 🙂

! means a “dangerous” version of a method. I’m not sure what a join  
can do that’s dangerous. Many ! methods change their receivers, but  
you can’t change an array object into a string object.

David

–  
David A. Black (removed\_email\_address@domain.invalid)  
Ruby Power and Light, LLC ([http://www.rubypowerandlight.com](http://www.rubypowerandlight.com))

“Ruby for Rails” chapters now available  
from Manning Early Access Program! [Ruby for Rails](http://www.manning.com/books/black)

---

<div class="post-metadata">

**Author:** ![g0nzo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/3bc359/32.png) [@g0nzo](https://www.ruby-forum.com/u/g0nzo)\
**Post date:** [March 14, 2006, 4:32pm UTC](https://www.ruby-forum.com/t/how-to-write-version-of-non-method/81724/4 "2006-03-14T16:32:59Z")

</div>

> you can’t change an array object into a string object

With all these one\_line\_that\_does\_billions\_of\_things methods in ruby i  
tried to reuse my array variable to store a string, so i won’t have to  
introduce new variable. I forgot that it will be different object 🙂
