我想实现这样的目标:
def to_indexed_json
{
if source.respond_to?(:app_id)
app_id: source.app_id
end
id: self.id,
content: self.content
}.to_json
end
我想实现这样的目标:
def to_indexed_json
{
if source.respond_to?(:app_id)
app_id: source.app_id
end
id: self.id,
content: self.content
}.to_json
end
def to_indexed_json
result = {id: self.id, content: self.content}
result.merge!(app_id: source.app_id) if source.respond_to?(:app_id)
result.to_json
end
data = Hash.new
if source.respond_to?(:app_id)
data['app_id']: source.app_id
end
data['id']: self.id,
data['content']: self.content
data.to_json