Send instance method to module

Posted by Matchu on Stack Overflow See other posts from Stack Overflow or by Matchu
Published on 2010-04-18T00:42:07Z Indexed on 2010/04/18 0:53 UTC
Read the original article Hit count: 437

Filed under:
|
|

Given the following module,

module Foo
  def bar
    :baz
  end
end

def send_to_foo(method)
  # ...?
end

send_to_foo(:bar) # => :baz

What code should go in send_to_foo to make the last line work as expected? (send_to_foo is obviously not how I would implement this; it just makes clearer what I'm looking for.)

I expected Foo.send(:bar) to work at first, but it makes sense that it doesn't. It would if the method were defined as def self.bar, but that's no fun.

© Stack Overflow or respective owner

Related posts about ruby

Related posts about module