Re: In-place parameter modification
- From: Judson Lester <nyarly@xxxxxxxxx>
- Date: Fri, 30 Oct 2009 19:25:00 -0500
[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/.
.
- Follow-Ups:
- Re: In-place parameter modification
- From: 7stud --
- Re: In-place parameter modification
- References:
- In-place parameter modification
- From: Dave Anderson
- In-place parameter modification
- Prev by Date: In-place parameter modification
- Next by Date: mtime.max
- Previous by thread: In-place parameter modification
- Next by thread: Re: In-place parameter modification
- Index(es):
Relevant Pages
|