Skip to content

Instantly share code, notes, and snippets.

@creadone
Last active February 24, 2021 23:46
Show Gist options
  • Save creadone/370ded3835c085c2389dfc8499c40a80 to your computer and use it in GitHub Desktop.
Save creadone/370ded3835c085c2389dfc8499c40a80 to your computer and use it in GitHub Desktop.
Return instances from class and build from_json
require "json"
struct Container
include JSON::Serializable
property a : Int32
property b : String
property c : String
property d : String
def initialize(@a, @b, @c, @d)
end
def self.build_instance
self.new(a: 2, b: "b", c: "c", d: "d")
end
end
p! Container.from_json(%({"a": 2, "b": "b", "c": "c", "d": "d"}))
p! Container.new(a: 2, b: "b", c: "c", d: "d")
p! Container.build_instance
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment