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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:41:43+00:00 2026-05-27T19:41:43+00:00

Im working with a class, containing large instance arrays. Whenever I initialize a class

  • 0

Im working with a class, containing large instance arrays.

Whenever I initialize a class like this, e.g. i = Image.new, I get a lot of junk output from my arrays (@r, @g, @b – ~300k values each).

 class Image

   def initialize(width=640, height=480, brightness=64)
     @width, @height, @brightness = width, height, brightness
     self.load('usart.dat')
   end

   def load(file='usart.dat')
     self.reset
     f = IO.read(file, @height * @width * 2, 0)

     # Parsing the datafile, saving data in @r, @g, @b, @gray etc

     end

     return self
   end

   # ... More methods
 end

Question is, how can I either silence the output (all results are saved to a file, never viewed in the console) or make an initializer NOT inspect self. I want to return self, since I want to stack methods, e.g. image.load('file').binary.grayscale.save(:bin).

  • 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-27T19:41:44+00:00Added an answer on May 27, 2026 at 7:41 pm

    The output you are seeing is the result of your object’s to_s (or inspect). You can define/overwrite to_s (or inspect) for your classes to produce less output. E.g.

    irb(main):001:0> class Foo
    irb(main):002:1>   def initialize
    irb(main):003:2>     @a = @b = @c = @d = 42
    irb(main):004:2>   end
    irb(main):005:1>
    irb(main):006:1*   def to_s
    irb(main):007:2>     'a Foo object'
    irb(main):008:2>   end
    irb(main):009:1> end
    => nil
    irb(main):010:0> h = Foo.new
    => a Foo object
    irb(main):011:0>
    

    Regarding to_s/inspect: irb calls inspect which normally just calls to_s (see ruby-doc). So, defining to_s should normally work. However, if there is an inspect not calling to_s in the class (or its ancestors), this inspect has to be overwritten.

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

Sidebar

Related Questions

I am working on the redesign of an existing class. In this class about
I am working with a large xml file containing unbounded collections. The idea is
Does anyone have a working class or function to create the hashed email that
using System; using System.IO; using System.Net; using System.Text.RegularExpressions; namespace Working { class Program4 {
I have a working wrapper class for Dallmeier camera devices, It contains a callback
I'm working on a class that inherits from another class, but I'm getting a
I'm working on a class that is storing a 2D array of class MyType
I'm working on a class assignment that started small, so I had it all
I am working on a class library using C#. I have designed 3 main
I'm working on a class project to build a little Connect4 game in Java.

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.