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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T10:57:52+00:00 2026-06-11T10:57:52+00:00

#!/usr/local/bin/ruby class OReport attr_accessor :id, :name def initialize(id, name, desc) @id = id @name

  • 0
#!/usr/local/bin/ruby
class OReport
   attr_accessor :id, :name
   def initialize(id, name, desc)
      @id       = id
      @name     = name
      @desc     = desc
   end
end

reports = Array.new
reports << OReport.new(1, 'One', 'One Desc')
reports << OReport.new(2, 'Two', 'Two Desc')
reports << OReport.new(3, 'Three', 'Three Desc')

How do I now search “Reports” for 2, so that I can extract name and description from it?

  • 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-11T10:57:53+00:00Added an answer on June 11, 2026 at 10:57 am

    If the primary use for reports is to retrieve by id, then consider using a hash instead:

    reports = {}
    reports[1] = OReport.new(1, 'One', 'One Desc')
    reports[2] = OReport.new(2, 'Two', 'Two Desc')
    reports[3] = OReport.new(3, 'Three', 'Three Desc')
    
    p reports[2].name    # => "Two"
    

    Hash lookup is usually faster than array lookup, but more important, it’s simpler.

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

Sidebar

Related Questions

Whenever I open a new terminal window I now get: -bash: /usr/local/bin/heroku: /usr/local/bin/ruby: bad
/usr/local/bin/ruby -rrubygems -e require 'redgreen' /usr/local/lib/ruby/gems/1.8/gems/rspec-1.3.0/bin/spec --autospec <files_here> -O spec/spec.opts invalid option: --autospec Test::Unit
My hosting company requires me to put #!/usr/local/bin/ruby at the top of every RB
I'm getting this warning in my Test::Unit output... /usr/local/bin/ruby -I.:lib:test -rtest/unit -e %w[test/functional/sessions_controller_test.rb].each {
I have both ruby and rails installed in: /usr/local/bin/ruby /usr/bin/ruby /usr/local/bin/ruby This is causing
Here is my terminal output. Anand@luckydev:~ $ which ruby /usr/local/bin/ruby Anand@luckydev:~ $ rvm list
sudo gem install mysql — –with-mysql-config=/usr/local/mysql/bin/mysql_config /usr/local/lib/ruby/1.9.1/optparse.rb:1262: warning: regexp match /.../n against to UTF-8
I try command bundle install --local but it show issue: -bash: /usr/local/bin/bundle: /usr/local/bin/ruby: bad
I am getting a segmentation fault. Should which ruby return /usr/local/bin? maletor$ rails generate
This command is my problem: /usr/local/bin/ruby **script/runner** --environment=production app/jobs/**my_job.rb** -t my_arg `my_job.rb` is my

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.