Skip to content

Instantly share code, notes, and snippets.

@ybenjo
Created May 12, 2015 02:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ybenjo/515809a0f405f834349f to your computer and use it in GitHub Desktop.
Save ybenjo/515809a0f405f834349f to your computer and use it in GitHub Desktop.
hoge
require 'json'
class Hoge
def initialize
@a=1
@b='hoge'
@c={:a => 1}
end
def to_json
h = { }
self.instance_variables.each do |v|
h[v] = self.instance_variable_get(v)
end
h.to_json
end
end
hoge = Hoge.new
p hoge.to_json
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment