Forum: Ruby on Rails How to write ! version of non ! method?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
F639e0cdf2fa098b535d6ec766b2aee1?d=identicon&s=25 Szymon Nowak (g0nzo)
on 2006-03-14 15:47
Hi!

How to write i.e. array.join! based on array.join method?
119af50160cabfe1fb6f2f05f5018c64?d=identicon&s=25 James Ludlow (Guest)
on 2006-03-14 15:53
(Received via mailing list)
On 3/14/06, szymek <g0nzo@o2.pl> 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
1fba4539b6cafe2e60a2916fa184fc2f?d=identicon&s=25 unknown (Guest)
on 2006-03-14 16:05
(Received via mailing list)
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 (dblack@wobblini.net)
Ruby Power and Light, LLC (http://www.rubypowerandlight.com)

"Ruby for Rails" chapters now available
from Manning Early Access Program! http://www.manning.com/books/black
F639e0cdf2fa098b535d6ec766b2aee1?d=identicon&s=25 Szymon Nowak (g0nzo)
on 2006-03-14 16:32
> 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 :)
This topic is locked and can not be replied to.