Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
以下代码行如何与ruby on rails 中的jbuilder一起使用:
json.(institute, :id, :name, :title, :updated_at)
调用中没有方法名称。有人可以解释这里的幕后情况吗?
该代码将调用callobject 上命名的方法json,这是一个示例:
call
json
class Test def call(*args) puts args.inspect end end t = Test.new t.(:something, 1, 2) => [:something, 1, 2]
您也可以使用method_missing方法获得类似的效果。
method_missing