On 17.01.2007 18:21, Neutek wrote:
> Cool... I think this works :-)
> 
> 
> #does not work when trying to send an entire mathematical expresion as
> a param
> def sigma(floor, to_do, cap)
> 	x = 0
> 	floor.upto(cap) {|i|
> 		#x += i.send(to_do)
> 		x += to_do[i]
> 	}
> 	return x
> end
> puts sigma(4, lambda{|x| x ** 2}, 20)
> 
> Thanks a million!

Basically if you think this further through, what you are trying to do 
is already part of Ruby's standard lib.  The method is #inject.  I think 
I used it in one of my postings.  Your piece above becomes

puts (4..20).inject(0) {|s,x| s + x ** 2}

or, to more directly translate using #upto

require 'enumerator'
puts 4.to_enum(:upto, 20).inject(0) {|s,x| s + x ** 2}

Cheers

	robert