title: Ruby method lookup from a dispatch table in a module
body: <p>I'm trying to create a concern for a model, but this is a basic Ruby method lookup problem not a Rails issue per se.</p>
  
  <p>I'd like my concern to provide the ability to format a value, by selecting a formatting method based on some characteristic of the value. In the abstracted example below, I want to invoke the <code>foo</code> formatter if the value to be formatted has an <code>:attribute</code> with value <code>:a_characteristic</code>. In particular, I want a dispatch table in which I can map from characteristics to formatting functions.</p>
  
  <p>Here's my attempt:</p>
  
  <pre class="lang-rb prettyprint-override"><code>module FormatConcern
    FORMATTERS = {
      a_characteristic: -&gt;(v){foo v}
    }
  
    def format( v )
      FORMATTERS[v[:attribute]].call( v )
    end
  
    def foo( v )
      "A value with #{v[:foo]}"
    end
  end
  
  class ModelWithConcern
    include FormatConcern
  end
  
  test_value = {attribute: :a_characteristic,
                foo: "bar"}
  m = ModelWithConcern.new
  puts "formatted value: #{m.format( test_value )}"
  </code></pre>
  
  <p>When I execute this code, the lookup of the <code>foo</code> method fails:</p>
  
  <pre><code>$ ruby concern_test.rb 
  concern_test.rb:3:in `block in &lt;module:FormatConcern&gt;': undefined method `foo' for FormatConcern:Module (NoMethodError)
  from concern_test.rb:7:in `call'
  from concern_test.rb:7:in `format'
  from concern_test.rb:22:in `&lt;main&gt;'
  </code></pre>
  
  <p>I thought I understood how Ruby looks up method names in a class, but clearly I don't understand it well enough! How can I refer to the <code>foo</code> method from the lambda functions in my dispatch table?</p>