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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T22:28:12+00:00 2026-06-02T22:28:12+00:00

I am currently doing pragmatic studios course and this is some code I wrote

  • 0

I am currently doing pragmatic studios course and this is some code I wrote for one of the exercises. When I run the code I get an object id in addition to the method I intended to call. The exercise creates a game where you can increase or decrease a players health using a blam or w00t method.

    class Player ##creates a player class
attr_accessor :fname, :lname, :health
def initialize fname, lname, health=100
 @fname, @lname, @health = fname.capitalize, lname.capitalize, health
end

def to_s
   #defines the method to introduce a new player
   #replaces the default to_s method 
  puts "I'm #{@fname} with a health of #{@health}."
end

def blam #the method for a player to get blammed?
  @health -= 10
  puts "#{@fname} got blammed!"
end
def w00t #the method for a player getting wooted
  @health += 15
  puts "#{@fname} got w00ted"
end
end
larry = Player.new("larry","fitzgerald",60)
curly = Player.new("curly","lou",125)
moe = Player.new("moe","blow")
shemp = Player.new("shemp","",90)

puts larry
puts larry.blam
puts larry
puts larry.w00t
puts larry

My output looks like this:

I'm Larry with a health of 60.
#<Player:0x10e96d6d8>
Larry got blammed!
nil
I'm Larry with a health of 50.
#<Player:0x10e96d6d8>
Larry got w00ted
nil
I'm Larry with a health of 65.
#<Player:0x10e96d6d8>

I can’t figure out why the object ids (or nil) is printed to the console when I run the code.
Thanks!

  • 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-02T22:28:13+00:00Added an answer on June 2, 2026 at 10:28 pm

    Because your functions should be returning strings, but they are actually returning the result of puts "something"

    do this instead:

    def w00t
     @health += 15
     "#{@fname} got w00ted"
    end
    

    Then when you do puts obj.w00t, it will perform the action, and return the string.

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

Sidebar

Related Questions

I'm currently doing something like this in some code I'm working on right now:
I am currently doing the following with some jQuery, $(.template-choice).live(click, function(event){$.post($(this).attr('href'), function(data) { console.log(data);
I'm currently doing some tests using Cairo to replace some existing GDI/GDI+ code in
I'm currently doing a project in C# working with windows forms. During the course
I'm currently doing some last-measure optimizations, mostly for fun and learning, and discovered something
I am currently doing this, but I am doing something wrong :): <Style TargetType={x:Type
I am currently doing some network programming and had a couple questions concerning timeouts.
I am currently doing something like this: myFunc(tracer); function tracer(message:String):void{ trace(message); } function myFunc(callback:Function):void{
I'm currently doing this query to find the guy who makes the most calls:
I am currently doing some kind of reporting system.the figures, tables, graphs are all

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.