From: salamond Date: 2012-11-12T17:15:03+09:00 Subject: how to define method with variables in arg list --e89a8fb20418df6a8004ce47e576 Content-Type: text/plain; charset=ISO-8859-1 Hi, all. I'm re-factoring code. with some duplicated code like: Class Gui def add_user(name, age, sex, location) @agent.post(url + '/user', {'name'=>name, 'age'=>age, 'sex'=>sex, 'location'=>location}) end def add_class(name, floor, room_number) @agent.post(url + '/classroom', {'name' => name, 'floor'=>floor, 'room_number'=>room_number}) end end Agent will format this into an html get/post request. I want to do this in a rails format. e.g. class Gui < Base method :add_user, :name, :age, :sex, :location method :add_class, :name, :floor, :room_number end class Base class << self def method(method_name, *args) define_method(method_name) |*args| # problem is here. how can I define a method, with dynamic numbers of variables? end end end end thanks Jaordzz --e89a8fb20418df6a8004ce47e576 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Hi, all.

I'm re-factoring code. with some duplicated= code like:

Class Gui
def add_user(name,= age, sex, location)
=A0 @agent.post(url + '/user', {'= ;name'=3D>name, 'age'=3D>age, 'sex'=3D>sex, &#= 39;location'=3D>location})
end

def add_class(name, floor, room_number)
=A0 @agent.post(url + '/classroom', {'name' =3D>= ; name, 'floor'=3D>floor, 'room_number'=3D>room_numbe= r})
end
end

Agent will format this into= an html get/post request.

I want to do this in a = rails format.
e.g.
class Gui < Base
=A0 me= thod :add_user, :name, :age, :sex, :location
=A0 method :add_class, :name, :floor, :room_number
end
=

class Base
=A0 class << self
= =A0 =A0 def method(method_name, *args)
=A0 =A0 =A0 define_method(= method_name) |*args| # problem is here. how can I define a method, with dyn= amic numbers of variables?=A0
=A0 =A0 =A0 end
=A0 =A0 end
=A0 end
end<= /div>


thanks

Jao= rdzz
--e89a8fb20418df6a8004ce47e576--