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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T15:30:22+00:00 2026-06-04T15:30:22+00:00

I am an RoR newbie. I have created a small application in ruby which

  • 0

I am an RoR newbie. I have created a small application in ruby which has small functions to execute the code.

e.g.

 def abc(xyz)
    some code
 end

 def ghi(xyz)
    some code
 end

 def jkl(output)
    some code
 end

 xyz = abc[ARGV(0)]
 output = ghi(xyz)
 puts jkl(output)

Now, when I run this code in command prompt using ruby .rb, it executes nicely and returns the desired results. But when I try to create a class and add this whole code to it e.g.

 class Foo
     def abc(xyz)
    some code
 end

 def ghi(xyz)
    some code
 end

 def jkl(output)
    some code
 end

 xyz = abc[ARGV(0)]
 output = ghi(xyz)
 puts jkl(output)
 end

It generates the error like “undefined method ‘abc’ for Foo:Class (NoMethodError)”

All I want to ask is that how shall I add this code to a class so that it can become more pluggable and get the desired results.

Thanks in advance.

  • 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-04T15:30:24+00:00Added an answer on June 4, 2026 at 3:30 pm

    As this is written, these are all instance methods. You need to make them class methods like these two examples, or you could leave them as is and create an instance of the class. Either way, you should probably move the last three statements outside the class definition.

    class Foo
      class << self
        def abc(xyz)
          some code
        end
    
        def ghi(xyz)
          some code
        end
    
        def jkl(output)
          some code
        end
      end
    end
    xyz = Foo.abc('something')
    output = Foo.ghi(xyz)
    puts Foo.jkl(output)
    

    OR….

    class Foo
      def self.abc(xyz)
        some code
      end
    
      def self.ghi(xyz)
        some code
      end
    
      def self.jkl(output)
        some code
      end
    end
    xyz = Foo.abc('something')
    output = Foo.ghi(xyz)
    puts Foo.jkl(output)
    

    EDIT: To answer your question in the comments, this is how you would instantiate the class and call using instance methods.

    class Foo
      def abc(xyz)
        some code
      end
    
      def ghi(xyz)
        some code
      end
    
      def jkl(output)
        some code
      end
    end
    bar = Foo.new
    xyz = bar.abc('something')
    output = bar.ghi(xyz)
    puts bar.jkl(output)
    

    If you don’t have any Ruby learning materials yet, you might want to check out Chris Pine’s tutorial, which includes a section on classes and how they work. As for books, here is a great book for Ruby in general and here is a question regarding books for Rails. I would suggest getting a decent grasp of Ruby before getting too deep into Rails.

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

Sidebar

Related Questions

I have a RoR application running on box1...it obviously has Ruby, RubyGems, and Rails
I have a RoR application (ruby v1.8.7; rails v2.3.5) that is caching a page
I am a complete newbie in working with a Ruby on Rails (RoR) application.
I have RoR 3.0 web application which is acting as an OAuth API provider.
WARNING: Complete newbie to RoR and Ruby alert! * I have a login method
I'm a newbie to RoR - I have three models: Customer , Job and
ROR Sample Application URL - http://sixrevisions.com/web-development/how-to-create-a-blog-from-scratch-using-ruby-on-rails/ I tried above reference for creating a blog
My application is in RoR I have an action/view called showsummary where the ID
I'm learning RoR through this tutorial . In tute, an application.html.erb file is created
Using Ruby/RoR - The year is a string in the model/view. How do I

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.