Created
September 2, 2011 13:38
-
-
Save akinsgre/1188605 to your computer and use it in GitHub Desktop.
JSON generation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ruby 1.9.2 | |
require 'json' | |
class Item | |
def initialize(name, description ) | |
@name = name | |
@description = description | |
end | |
def to_json(*a) | |
{"name" => @name, "description" => @description}.to_json(*a) | |
end | |
end | |
item = Item.new("Grain", "Base and Specialty Malts") | |
puts item.to_json(:only => [:name]) | |
# {"name":"Grain","description":"Base and Specialty Malts"} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment