Skip to content

Latest commit

 

History

History
109 lines (66 loc) · 2.4 KB

classes.md

File metadata and controls

109 lines (66 loc) · 2.4 KB

Classes

{id: classes}

Empty Class definition

{id: empty-class-definition} {i: class}

Class with attributes

{id: class-with-attributes} {i: initialize} {i: @}

Class with getters

{id: class-with-getters}

Class with setter

{id: class-with-setters}

Class with getters and setter (property)

{id: class-with-getters-and-setters} {i: property} {i: getter}

Class with property with default value

{id: class-with-property-with-default-value} {i: property}

Class with declared getter and default value

{id: class-with-declared-getter-and-default-value} {i: getter}

Class with declared getter

{id: class-with-declared-getter} {i: getter}

Serialize Crystal-lang class to/from JSON from_json to_json

{id: class-serialization-to-from-json} {i: to_json} {i: from_json} {i: JSON::Serializable}

Compare objects for equality

{id: compare-objects-for-equality}

Normally using == between two instances will only return true if they are the exact same objects in the memory. If "only" all the attributes are the same then == will be false.

To be able to compare two objects based on their attributes only we can used the def_equals macro.

Singleton using class properties

{id: singleton-using-class-properties} {i: class_property}

Singleton using class properties with default values

{id: singleton-using-class-properties-with-defaults} {i: class_property}

Class monkey-path add method

{id: class-monkey-path-add-method}

Stringification to_s

{id: class-stringification} {i: to_s}