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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:36:49+00:00 2026-05-26T17:36:49+00:00

I have an ActiveRecord class – lets call it comments – which has an

  • 0

I have an ActiveRecord class – lets call it comments – which has an author attribute.

In my code at one point I have passed an instance of comments and the symbol :author to a helper method. I now find myself wanting to access the author attribute and was wondering if there’s a way of doing this with what I have.

I can use comment.read_attribute :author but I can’t use comment.write_attribute :author as it is a private method.

I suspect I’m missing something quite obvious. Any ideas?

  • 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-26T17:36:49+00:00Added an answer on May 26, 2026 at 5:36 pm

    You can use instance_eval

    irb(main):006:0> class MyClass
    irb(main):007:1> attr_accesor :length
    irb(main):008:1> end
    irb(main):012:0> c = MyClass.new
    => #<MyClass:0x27d6458>
    irb(main):016:0> b = 11
    => 11
    irb(main):019:0> c.instance_eval( "self.length = #{b}" )
    => 11
    irb(main):020:0> c.length
    => 11
    irb(main):019:0> c.instance_eval( "self.length" )
    => 11
    

    or

    irb(main):021:0> c.send :length
    => 11
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an ActiveRecord::Base class which needs to have one field's value picked as
I have an ActiveRecord called Name which contains names in various Languages . class
Lets say there is a activerecord class called user, which is representative of user
I have a Model called Todo.rb which has an attribute called asset which is
I have a activerecord model which has an array in it of say: $sessions.
I have an ActiveRecord model, Foo , which has a name field. I'd like
Lets say I am wrapping an ActiveRecord class for some reason and I have
I have an ActiveRecord Model, PricePackage. That has a before_create call back. This call
I have a ruby method (deactivate!) that is on an activeRecord class. However, I
I have an ActiveRecord before_save method throwing an odd error: class MyThing < ActiveRecord::Base

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.