hashable
The hashable package defines Hashable, a base struct whose to_hash() method returns an instance’s variables as a hashmap. Inherit from it to make a struct easy to serialize or log.
struct Config < Hashable fn new(host, port) @host = host @port = port endend
println Config.new("localhost", 8080).to_hash() # {"host": "localhost", "port": 8080}Hashable struct
Section titled “Hashable struct”When inherited, structs receive a to_hash() function that returns their instance variables as a hashmap.
.to_hash
Section titled “.to_hash”to_hash(): hashmapReturns instance variables as a hashmap.
Returns hashmap — Returns a hashmap containing instance variables as key-value pairs.