Note that there are some explanatory texts on larger screens.

plurals
  1. POShow object as name value pair instead of instance variable
    primarykey
    data
    text
    <p>I'm trying to implement a gem that is redis wrapper for other library i.e to store the ruby object in the redis.</p> <p>all work well but what I want is when I do </p> <p><code>[Class].all</code> It give object like this </p> <p><code>[#&lt;Peagon:0x007fba589de3a0 @name="a", @omg=false ,@payload="one",@handler="--- one\n...\n"&gt; ,#&lt;Peagon:0x007fba589de1a0 @name="b", @omg=true,@payload="two",@handler="--- two\n...\n"&gt;]</code></p> <p>but instead I want it to be look like how active record present the object</p> <p><code>[#&lt;Peagon name: "a",omg: false ,handler: "--- one\n...\n"&gt; ,#&lt;Peagon name="b", omg: true,handler: "--- two\n...\n"&gt;]</code></p> <p>The reason for this that I not interested in showing the user the <code>@payload</code> instance variable because that is something set by the other library </p> <p>so basically like this happen <strong>[My gem]</strong> </p> <pre><code>class Peagon include SomeModule attr_accessor :name,:omg,:handler def initialize(options) @name = options[:name] @omg = options self.payload_object = options[:payload_object] end end </code></pre> <p>Now the <strong>[Other Library]</strong> has this <code>module</code> in it</p> <pre><code>module SomeModule def payload=(object) @payload ||= object self.handler = @payload.to_yaml end def payload @payload ||= YAML.load(self.handler) end </code></pre> <p>end </p> <h2>NOTE :</h2> <p>Overwriting the payload method from other library is not in my mind </p> <p>Now is it possible to get what I meant above </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload