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 874351
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T11:05:27+00:00 2026-05-15T11:05:27+00:00

In my Rails app, I am used to using syntax like the following in

  • 0

In my Rails app, I am used to using syntax like the following in a number of places, including helpers/application_helper.rb:

def my_method(x,y)
  return x+y
end

I am also used to calling the resulting method from basically anywhere in my app using syntax like this:

my_method(2,3)

However, I’d like to be able to use syntax like like this:

class_from_my_rails_app.my_method(3)

How and where do I define my_method so I can use it like this?

I’m happy to consult the documentation, but I just don’t know what the latter style is called. What do you call it?

Many thanks,

Steven.

  • 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-15T11:05:28+00:00Added an answer on May 15, 2026 at 11:05 am

    THe thing you want to create is called an instance method. Implemented as follows:

    class YourClass
    
      def initalize(x)
        @x =x
      end
    
      def do_something(y)
        @x + y
      end
    
    end
    

    which you would use a follows:

    my_class = YourClass.new(20)
    
    puts my_class.do_something(10)
    => 30
    

    But actually this is so fundamental to object oriented programming and ruby that i am surprised to even see this question.

    I would suggest reading up on ruby as a language, a very good book t get you started is The Well-grounded Rubyist, that starts from all the basics and works it’s way up into all the details.

    I hope this helps. If i misunderstood your question, i apologise, and would be glad to elaborate on any part.

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

Sidebar

Related Questions

I am using jruby, i want use pagination for my rails app i used
I am creating a rails app and have used this code in one of
I want to use mysql with a rails app (I have never used mysql
My rails app is set up using a mysql database. When I do a
My rails app talks to a couple different APIs, and I'd like to write
I have few variables which are used system-wide in my rails app. It runs
I have a rails app running on Heroku. I am using paperclip for some
I'm working more on my first live Rails app using 3.1.0 with M. Hartl's
The first rails app I wrote used the hand-rolled authentication from railstutorial . For
I have a rails app that is using Devise, with a User model, no

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.