Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.lang.ruby
Extracting array values in Object.send.
warhero
1/13/2007 9:05:00 PM
How can I exract array values when using Object.send. See the example
below.
class TestSend
def test( arg1, arg2, arg3)
puts arg1
puts arg2
puts arg3
end
end
t = TestSend.new
t.send('test', 'hey', 1, 'rrr')
args = ['hey',1,'rrr']
t.send('test', args) #this throws an argument error, 3 for 1..
Thanks.
--
Posted via
http://www.ruby-...
.
1 Answer
Suraj Kurapati
1/13/2007 9:37:00 PM
0
Aaron Smith wrote:
> How can I exract array values when using Object.send. See the example
> below.
>
> class TestSend
>
> def test( arg1, arg2, arg3)
> puts arg1
> puts arg2
> puts arg3
> end
>
> end
>
> t = TestSend.new
> t.send('test', 'hey', 1, 'rrr')
>
> args = ['hey',1,'rrr']
> t.send('test', args) #this throws an argument error, 3 for 1..
Use the splat operator to expand the array into individual method
arguments:
t.send(:test, *args)
--
Posted via
http://www.ruby-...
.
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
Extracting array values in Object.send.
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password