mercredi 13 avril 2016

Possible to retrieve value of instance which singleton class is attached to?

Here is a example of singleton class:

class MyPost < ActiveRecord::Base
  def initialize(title)
    @title = title
  end
end

post = MyPost.new(:title => 'post title)

def post.some_method
  #is it possible to retrieve value of `post`?
  my_post_title = post.title #???. Not working now
end

Is it possible to refer back to post in def post.some_method?

Aucun commentaire:

Enregistrer un commentaire