Last active
February 24, 2021 23:46
-
-
Save creadone/370ded3835c085c2389dfc8499c40a80 to your computer and use it in GitHub Desktop.
Return instances from class and build from_json
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
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