Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.ruby > #3515

Setting a 'reference' inside the method body

From Peter Szinek <peter.szinek@gmail.com>
Newsgroups comp.lang.ruby
Subject Setting a 'reference' inside the method body
Date 2011-04-26 09:55 -0500
Organization Service de news de lacave.net
Message-ID <ce11d8adf31eab2c2a5b15b2b4337a74@ruby-forum.com> (permalink)

Show all headers | View raw


Hey guys,

Can Ruby do this in some way:

def foo(bar)
  #DO SOMETHING with bar here resulting in baz being set to {}
end

baz = {:fluff => :ork}
foo(baz)
#baz should be {} now

I'd like to use it in a code which calls a callback, (the foo method in
this case) but the callback is called from multiple places, and only
inside foo() we know whether we want to empty the array or not... it
would be complicated to return something from foo() with the current
architecture (based on which we could empty the hash or not).


My Ruby version is JRuby 1.6 if that makes any difference.

Cheers,
Peter

-- 
Posted via http://www.ruby-forum.com/.

Back to comp.lang.ruby | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Setting a 'reference' inside the method body Peter Szinek <peter.szinek@gmail.com> - 2011-04-26 09:55 -0500
  Re: Setting a 'reference' inside the method body Xavier Noria <fxn@hashref.com> - 2011-04-26 10:04 -0500
    Re: Setting a 'reference' inside the method body Brian Candler <b.candler@pobox.com> - 2011-04-26 10:28 -0500
      Re: Setting a 'reference' inside the method body Charles Oliver Nutter <headius@headius.com> - 2011-04-27 00:46 -0500
        Re: Setting a 'reference' inside the method body Robert Dober <robert.dober@gmail.com> - 2011-04-27 01:04 -0500

csiph-web