Ruby Array args to function

Sage
Posts: 1,403
Joined: 2005.07
Post: #1
in lua you can do somthing like
Code:
function printEveryArg(...)
    for _, item in pairs( arg ) do
    io.write(item.."\n")
    end
end

so the function can take any number of args,
How do you do this in ruby?
I cant seem to find out anywhere..

Sir, e^iπ + 1 = 0, hence God exists; reply!
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #2
Code:
def printEveryArg(*args)
    puts args.join("\n")
end

(args is a standard ruby array)
Quote this message in a reply
Sage
Posts: 1,403
Joined: 2005.07
Post: #3
Thanks Keith.
Im making a 2D Rigid Body physics engine with the RubyGameShell to try and learn ruby better..
So im on my way.. Smile

Sir, e^iπ + 1 = 0, hence God exists; reply!
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Ruby on Rails setting Time to NULL BeyondCloister 3 3,883 Nov 21, 2007 09:56 AM
Last Post: AndyKorth
  Ruby, MacPorts, Firewalls BeyondCloister 3 4,090 Nov 6, 2007 04:57 PM
Last Post: OneSadCookie
  Ruby: Resources for Learning iefan 10 6,917 Jul 4, 2007 08:54 AM
Last Post: ALX99066
  Ruby Gems and OpenGL Jaden 2 3,077 Apr 2, 2007 01:15 AM
Last Post: Jaden
  Embedding Ruby DesertPenguin 3 3,426 Jan 5, 2007 09:11 PM
Last Post: DesertPenguin