Created
December 18, 2014 17:49
-
-
Save zmoazeni/e317b78a8c37a2e2fc2a to your computer and use it in GitHub Desktop.
I've been using this instead of OpenStruct lately
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
SomeObj = Struct.new(:foo, :bar, :baz) do | |
def initialize(foo:, bar:, baz: 'is optional') | |
self.foo = foo | |
self.bar = bar | |
self.baz = baz | |
end | |
end | |
p SomeObj.new(foo: 1, bar: 2) | |
p SomeObj.new(foo: 1, bar: 2, baz: 'overridden') | |
some_hash = { foo: 'the foo', bar: 'the bar', baz: 'the baz'} | |
p SomeObj.new(some_hash) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment