Skip to content

Instantly share code, notes, and snippets.

@aereal
Created June 3, 2011 11:09
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 aereal/1006196 to your computer and use it in GitHub Desktop.
Save aereal/1006196 to your computer and use it in GitHub Desktop.
OpenStruct better than Class with attr_accessor
class Hoge
attr_accessor :hoge, :fuga
end
a = Hoge.new; b = Hoge.new
a.foo = :bar; b.foo = :bar
p a == b # -> false
require 'ostruct'
Fuga = OpenStruct
s = Fuga.new; t = Fuga.new
s.foo = :bar; t.foo = :bar
p s == t # -> true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment