Using define_method to create a method that takes arguments

W

Wes Gamble

How does one use define_method to create a method that can take
arguments?

Is that possible?

Wes
 
J

Joel VanderWerf

Wes said:
How does one use define_method to create a method that can take
arguments?

Is that possible?

Wes

Use a block that has arguments:

irb(main):003:0> class << self; define_method :foo do |x, *y| p x, y;
end; end
=> #<Proc:0xb7ca3f20@(irb):3>
irb(main):004:0> foo 1,2,3
1
[2, 3]
=> nil
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,211
Messages
2,571,092
Members
47,693
Latest member
david4523

Latest Threads

Top