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

  • SEARCH
  • Home
  • 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 6565341
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:04:56+00:00 2026-05-25T14:04:56+00:00

Rails has these cool properties that seem to be actually methods. For example: class

  • 0

Rails has these cool properties that seem to be actually methods. For example:

class SomeController < ApplicationController

  before_filter :authenticate!

end

What are these actually called and how would you create your own? For example, in one of my models I want to be able to have a dynamic property that selects an internal method for processing some results:

class MyModel < ActiveRecord::Base

    active_method :some_class_method

end

How would I set this up so I can set active_method like that and be able to access the active_method symbol as an instance var?

Edit for elaboration:

So give this starter below, I need to figure out how to define “selected_method” so that it defines a accessor or instance variable so “called_selected_method” calls “method_b”.

class MyClass

  selected_method :method_b

  def call_selected_method

  end

  private

  def method_a
    puts 'method_a'
  end

  def method_b
    puts 'method_b'
  end

end

c = MyClass.new
c.call_selected_method # should put 'method_b'
  • 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-05-25T14:04:56+00:00Added an answer on May 25, 2026 at 2:04 pm

    It’s actually just a method call to a method defined on the class. before_filter is provided by a ruby Module, which is mixed in to ActionController.

    Creating your own methods similar to before_filter is as easy as:

    1. Define a class method on your Class
    2. Call that method in any concrete implementations of your class.

    Some example code:

    class MyClass
      class << self
        def some_function(*args)
          # your code here
        end
      end
    
      some_function "foo"
    end
    

    If you wanted to abstract it further, you can put the class method in to a Module, and then include that module in to your class(es).

    UPDATE:

    In relation to your asking of how to get a call of some_function to set an instance variable on your class, you can’t, as class methods cannot affect specific instances of that class.

    I have to wonder, though… you’re writing a method that will just act as a proxy to your other method, and would be hard-coded in to the class definition. That offers no benefit to you, and would just make your code redundantly complicated.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Rails has these lovely chainable methods. How do I add my own? I thought
Rails has a nice idiom that makes it easy for you to have a
Ruby on Rails has magic timestamping fields that are automatically updated when a record
I'm aware that Rails has a few different levels for logging, but how can
The Paperclip plugin for Rails has a resize option that keeps the image in
Ruby on Rails has a screencast presentation they use to promote their framework that
Developing rails has become lots of fun over the year that I've done it,
I am pretty sure that Ruby has these (equivalents for __call, __get and __set
I am working on a Rails application that has user authentication which provides an
In Ruby on Rails, each model entity has a validate_on_ something hook method, that

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.