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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:13:54+00:00 2026-05-23T16:13:54+00:00

So I come from a background in Java where you can create a class

  • 0

So I come from a background in Java where you can create a class as such.

TestClass x = new TextClass();

and call its method like
x.shout();

I’m attempting to do something similar in ruby with no such look. This could be syntactical or it could be I don’t understand the concept of ruby and rails well.

So heres a class on a server in Ruby

class myResource< ActiveResource::Base
  self.site = "http://localhost:3008"
  def self.shout
    puts "I AM AN ACTIVE RESOURCE SHOUT!"
    puts " CAPS RAGE YEAH!"
    puts Time.now
  end
end

This sits on client side.

Heres the same class as an active record on server:

class myRecord < ActiveRecord::Base
  def self.shout
  puts "I AM AN ACTIVE RECORD SHOUT!"
  puts " CAPS RAGE YEAH!"
  puts Time.now
  end

end

So heres the result of what I’ve attempted.

On server in rails console:

?> myRecord.shout
I AM AN ACTIVE RECORD SHOUT!
 CAPS RAGE YEAH!
Wed Jul 13 10:17:33 +0100 2011
=> nil
>> 

On the client side however,

myResource.shout
NoMethodError: undefined method `shout' for myResource:Class
    from (irb):206
>>

In my mind this makes no sense as their almost identical and should be called as such.

If i instantiate either of them as

@test = myResource or myRecord.new(blah blah blah)

when i write @test.shout

I get the same undefined method.

My idea of what an object is in Ruby has been blown. Has anyone any advice on what I’m doing wrong here.

  • 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-23T16:13:55+00:00Added an answer on May 23, 2026 at 4:13 pm

    Ruby classes are always capitalized. Also, you do not reference self when you are declaring a regular method in a class.

    This is what you want:

    class MyRecord 
    
        def shout
            puts "I AM AN ACTIVE RECORD SHOUT!"
            puts "CAPS RAGE YEAH!"
            puts Time.now
        end
    
    end
    

    Then run it however you want:

    > MyRecord.new.shout
    => "I AM AN ACTIVE RECORD SHOUT!"
    => "CAPS RAGE YEAH!"
    => 2011-07-13 06:35:18 -0400
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I come from a java background. But I would like a cross-platform perspective on
I come from a java background, I know how to call methods from objects
I’m relatively new to working with Scala having recently come from a java background.
I come from a Java background, where packages are used, not namespaces. I'm used
I come from a Java background and with any servlets-based technology, it's trivial to
I come from more of a Java background. In the last year or two,
I come from a C++ background where I can use template mixins to write
I'm new to WPF and come from a WinForms background and have a fairly
I come from a PHP based background and my new years resolution was to
I come from a strong Java background and in recent years have been also

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.