我想做类似这样的事情:
require 'json'
class Person
attr_accessor :fname, :lname
end
p = Person.new
p.fname = "Mike"
p.lname = "Smith"
p.to_json
有可能吗?
require 'json'
,但是在普通的Ruby代码中可能需要。JSON是Ruby标准库的一部分,因此它随语言一起提供。 - the Tin Man