Skip to content

Instantly share code, notes, and snippets.

@chad
Created May 25, 2010 21:46
Show Gist options
  • Save chad/413735 to your computer and use it in GitHub Desktop.
Save chad/413735 to your computer and use it in GitHub Desktop.
# require 'ostruct'
# OpenStruct
class OStruct
def initialize
@attributes = {}
end
def method_missing(name, arg = nil)
if name.to_s =~ /=/
@attributes[name.to_s.sub(%r{=}, '')] = arg
else
@attributes[name.to_s]
end
end
end
person = OStruct.new
person.name = "Chad"
person.location = "CA"
puts person.location
dog = OStruct.new
dog.name = "Fido"
dog.breed = "Chihuahua"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment