I was meta-meta-programming, and had an issue when an #included method was called:

 1 anon = Module.new
 2 anon.class_eval do
 3   def self.included(base)
 4     debugger
 5     if some_method then
 6       # code
 7     else
 8       # more code
 9     end
10   end
11 end

The code above resulted in:

1 /Users/francois/Projects/project/lib/extensions.rb:214:in `included': undefined local variable or method `some_method' for #<Module:0x103305b20> (NameError)
2         from /Users/francois/Projects/project/lib/extensions.rb:245:in `include'
3         from /Users/francois/Projects/project/lib/extensions.rb:245:in `send'
4         ...

The debugger statement above just wouldn’t take: Ruby ran right over it. I happened to look at ruby-debug’s Rubygem spec file:

1 --- !ruby/object:Gem::Specification 
2 name: ruby-debug
3 ...
4 executables: 
5 - rdebug
6 ...

Oh, had never noticed the executables before… Sure enough, I managed to run under debugger control immediately:

 1 $ rdebug -I test test/functional/ad_spots_controller_test.rb [-4, 5] in /Users/francois/Projects/bloom/adgear-admin/test/functional/ad_spots_controller_test.rb
 2 => 1  require "test_helper"
 3    2  
 4    3  class AdSpotsControllerTest < ActionController::TestCase
 5    4  
 6    5    def setup
 7 /Users/francois/Projects/bloom/adgear-admin/test/functional/ad_spots_controller_test.rb:1
 8 require "test_helper"
 9 (rdb:1) 

From there, I was able to use (C)ontinue to end up on my debugger statement. Happy times ensued!

For the curious, the NoMethodError is because #some_method is defined on base, not on self. self in this context is the included module, while base is the place where we’re including it into.


Your Host

A picture of me

I am François Beausoleil, a Ruby on Rails and Scala developer. During the day, I work on Seevibes, a platform to measure social interactions related to TV shows. At night, I am interested many things. Read my biography.

Top Tags

Books I read and recommend


Projects I work on

Projects I worked on