Would someone please tell me how to make methods that have
other methods as parameters?  (My ultimate goal is to teach
Ruby basic calculus.)  For example, I'd like something
on the order of:
def at_zero(m()) # pickaxe says "you must use parentheses
                 # on a method call which is itself a
                 # parameter to another method"
  m(0)
end

When I try this, I run into trouble:

irb(main):001:0> require 'mathn'
true
irb(main):002:0> include Math
Object
irb(main):003:0> sin(0)
0.0
irb(main):004:0> def at_zero(m()) # first cut
irb(main):005:1> m(0)
irb(main):006:1> end
SyntaxError: compile error
(irb):4: parse error
def at_zero(m())
              ^
(irb):6: parse error
	from (irb):6
irb(main):007:0> class Method  # maybe I can get sin.at_zero
irb(main):008:1> def at_zero
irb(main):009:2> self(0)
irb(main):010:2> end
irb(main):011:1> end
SyntaxError: compile error
(irb):9: parse error
self(0)
     ^
	from (irb):11
irb(main):012:0> def at_zero(m)
irb(main):013:1> m(0)
irb(main):014:1> end
nil
irb(main):015:0> sin(0)
0.0
irb(main):016:0> at_zero(sin())
ArgumentError: wrong # of arguments(0 for 1)
	from (irb):16:in `sin'
	from (irb):16
irb(main):017:0> at_zero(sin)
ArgumentError: wrong # of arguments(0 for 1)
	from (irb):17:in `sin'
	from (irb):17
irb(main):018:0> at_zero(:sin) # desperation
NameError: undefined method `m' for #<Object:0x401ddc90>
	from (irb):13:in `at_zero'
	from (irb):18
irb(main):019:0> class Method  # try with explicit "self" param
irb(main):020:1> def at_zero(self)
irb(main):021:2> self(0)
irb(main):022:2> end
irb(main):023:1> end
SyntaxError: compile error
(irb):20: parse error
def at_zero(self)
                ^
	from (irb):23
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  Help, please!  Doomoo arigatoo

Regards, Bret Jolly (Jou Lii Bair)

For email, please remove the cow noises and underbar
from my domain name.


-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----==  Over 80,000 Newsgroups - 16 Different Servers! =-----