🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: pl.comp.lang.ruby
Article #268

Re: Argumenty via referencja?

#268
From: Jan Szumiec
Date: Tue, 31 Oct 2006 18:38
31 lines
2106 bytes
Maciej Pilichowski wrote:
> Hej,
>
>   Sorry, ze to tak a'la C++, ale to moj podstawowy jezyk. Z tego co
> sie zorientowalem, argumenty przekazywane sa przez wartosc. A jak
> przekazac je przez referencje?

Hmm... chyba nie do końca, przekazywanie przez wartość nie do końca
ma sens w tym języku, bo wszystko jest obiektem.

require 'test/unit'

class PassByReferenceTest < Test::Unit::TestCase
    def test_pass
        dict = { :klucz => :wartosc }
        assert_equal dict.object_id, fun(dict)
    end

    def fun(a)
        a.object_id
    end
end

>   Np. chcialem przeiterowac -- each -- wszystkie elementy tablicy i
> zmienic je na pisane malymi literami. Podejscie naiwne oczywiscie
> zmienia mi lokalny argument bloku, a nie element tablicy.

Hmm... dla stringów jest metoda :downcase.
Dla tablic, masz metody :select, :reject, :collect, :map, które robią
różne rzeczy na tablicach.
Technical Details
Message-ID: <1162319903.041666.247850@f16g2000cwb.googlegroups.com>
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!newsfeed.gazeta.pl!newsfeed.pionier.net.pl!newsfeed.gamma.ru!Gamma.RU!postnews.google.com!f16g2000cwb.googlegroups.com!not-for-mail
References: <fduek2horgk3ckbcmh74f6jlit073qnjhq@4ax.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!newsfeed.gazeta.pl!newsfeed.pionier.net.pl!newsfeed.gamma.ru!Gamma.RU!postnews.google.com!f16g2000cwb.googlegroups.com!not-for-mail
From: "Jan Szumiec" <jan.szumiec@gmail.com>
Newsgroups: pl.comp.lang.ruby
Subject: Re: Argumenty via referencja?
Date: 31 Oct 2006 10:38:23 -0800
Organization: http://groups.google.com
Lines: 32
Message-ID: <1162319903.041666.247850@f16g2000cwb.googlegroups.com>
References: <fduek2horgk3ckbcmh74f6jlit073qnjhq@4ax.com>
NNTP-Posting-Host: 83.13.74.122
Mime-Version: 1.0
X-Trace: posting.google.com 1162319908 28123 127.0.0.1 (31 Oct 2006 18:38:28 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Tue, 31 Oct 2006 18:38:28 +0000 (UTC)
In-Reply-To: <fduek2horgk3ckbcmh74f6jlit073qnjhq@4ax.com>
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1) Gecko/20061010 Firefox/2.0,gzip(gfe),gzip(gfe)
Complaints-To: groups-abuse@google.com
Injection-Info: f16g2000cwb.googlegroups.com; posting-host=83.13.74.122;   posting-account=FMiszA0AAABQtkerBRSLjEJiW7XY2eLK
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit