How does one use define_method to create a method that can take
arguments?
Is that possible?
Wes
···
--
Posted via http://www.ruby-forum.com/.
How does one use define_method to create a method that can take
arguments?
Is that possible?
Wes
--
Posted via http://www.ruby-forum.com/.
Wes Gamble wrote:
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
--
vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407
Wes Gamble wrote:
How does one use define_method to create a method that can take
arguments?Is that possible?
#!/usr/bin/ruby -w
class A
define_method(:trythis) { |a,b,c| puts a,b,c }
end
a = A.new
a.trythis("one","two","three")
one
two
three
a.trythis()
in `trythis': wrong number of arguments (0 for 3) (ArgumentError)
--
Paul Lutus
http://www.arachnoid.com