Skip to content

Instantly share code, notes, and snippets.

@astropanic
Created October 4, 2012 14:37
Show Gist options
  • Save astropanic/3833927 to your computer and use it in GitHub Desktop.
Save astropanic/3833927 to your computer and use it in GitHub Desktop.
ruby x.rb
{"title":"SHINY NEW TITLE","bar":"blah"}
require 'json'
class Foo
attr_accessor :title, :bar
def initialize
self.title = "shiny new title"
self.bar = "blah"
end
def html_attributes
hash = {}
instance_variables.each {|var| hash[var.to_s.delete("@")] = instance_variable_get(var) }
hash.merge! "title" => title.upcase
JSON.generate(hash)
end
end
f = Foo.new
puts f.html_attributes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment