Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8283621
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T10:47:52+00:00 2026-06-08T10:47:52+00:00

I created a module which is included in a class. In the module, I

  • 0

I created a module which is included in a class. In the module, I am trying to define a method that is the downcased version of a class name without Filter. So ShowFilter would have a method called show that returns the class Show. I get “NoMethodError:
undefined method `show’ for ShowFilter:Class”

module Filters

  module Base

    module ClassMethods

      @@filters = {}

      def filter name, &block
        @@filters[name] = block
      end

      def run query = {}
        query.each do |name, value|
          @@filters[name.to_sym].call(value) unless @@filters[name.to_sym].nil?
        end
        self
      end

      def self.extended(base)
        name = base.class.name.gsub(/filter/i, '')
        define_method(name.downcase.to_sym) { Kernel.const_get name }
      end


    end

    def self.included base
      base.extend ClassMethods
    end

  end

end


class ShowFilter
    include Filters::Base

    filter :name do |name|
        self.show.where(:name => name)
    end

end

EDIT: Example of use

class ShowController < ApplicationController
  def index
    ShowFilter.run params[:query]
  end
end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T10:47:53+00:00Added an answer on June 8, 2026 at 10:47 am

    When you define Filters::Base::ClassMethods, it evaluates self in that context so the method you’ll end up defining is ClassMethods.classmethods (since the gsub won’t do anything).

    Like the included hook you tapped into in Base, you want to use extended in ClassMethods:

    module Filters
      module Base
        module ClassMethods
    
          @@filters = {}
    
          def filter name, &block
            @@filters[name] = block 
          end 
    
          def run query = {} 
            query.each do |name, value| 
              @@filters[name.to_sym].call(value) unless @@filters[name.to_sym].nil? 
            end 
            Object.const_get(self.to_s.gsub('Filter', '')) 
          end 
    
          def self.extended(base) 
            define_method(base.to_s.downcase.gsub('filter', '').to_sym) do 
              Object.const_get(self.to_s.gsub('Filter', '')) 
            end 
          end 
        end 
    
        def self.included base 
          base.extend ClassMethods 
        end 
      end 
    end
    class ShowFilter 
      include Filters::Base 
    
      filter :title do |title| 
        self.show.where(:title => title) 
      end 
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've created a Dojo module which depends on dojox/data/JsonRestStore like this: define(my/MyRestStore, [dojo/_base/declare, dojox/data/JsonRestStore],
I've created a custom module (which currently only defines a new Exception class), and
I have a module in which I created a custom page with controller and
I have a module modA , which contains a synthesized submodule modB (created with
I'm currently developing a module for Drupal 6, in which I have created a
I'm trying to use thanos, which creates an extension module at runtime. Thanos is
I've created a webpage which is inherited from another class something like : class
I am trying to create a custom module which will capture order information each
I want create module which update list of usb devices automatically (not only mass
I have create a module which at this point does nothing but exist the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.