這裏是單例類的一個例子:可能檢索哪個單例類附加到的實例的值?
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
是否有可能重提post
在def post.some_method
?
downvoter可以指定什麼是錯誤的程序? – uday
'title'在調試中返回'nil'。 – user938363
我有兩種方式來做它..請看看哪一個適合你 – uday