Re: In-place parameter modification



[Note: parts of this message were removed to make it a legal post.]

Actually, chomp!(string) doesn't modify string, it modifies $_ (which, if I
recall correctly, is set by the -n and -p switches to ruby).

String#chomp! modifies the recipient.

Finally: ruby is a pass-by-reference language, so if you actually do make
changes the parameters of a method, the callers variables will change as
well. For instance:

def make_bacon(string)
string.replace "Chunky bacon."
end

hi = "hello"
make_bacon(hi)
hi #=> "Chunky bacon."

Judson

On Fri, Oct 30, 2009 at 4:38 PM, Dave Anderson <anderson@xxxxxxxxxxx> wrote:

Native to ruby are several methods that change passed-in parameters
in-place, such as chomp!(somestring). But I don't see any info on
creating these things myself. Is it possible to write methods that
change parameters this way?
--
Posted via http://www.ruby-forum.com/.



.



Relevant Pages