0

I have this class:

class SpecialAwesome
  module Controller
    def builder
      SpecialAwesome.with_member(current_member)

which fails saying:

NoMethodError: undefined method `with_member'

But then I see the method here at:

class SpecialAwesome
  module Options
    def with_member member
      self.class.new options.merge(:member => member)
    end

How come the other file doesn't recognize this method?

4

2 回答 2

2

The with_member method is defined as an instance method on SpecialAwesome::Options, not as a class method of SpecialAwesome. Probably, this is an issue.

于 2013-07-10T13:27:46.810 回答
1

with_member is not SpecialAwesome class method, but it is defined in Options module. To make it work as you expect, you can for example use extend method:

class SpecialAwesome
  module Options
    # ...
  end
  extend Options
  # ...
end

which will add methods defined in Options module as SpecialAwesome class methods.

于 2013-07-10T13:28:59.973 回答