讓我說我有一個結構,struct = %MyApp.MyModel{ filled_with_data: "true }
。如何在elixir中獲取struct name?
我怎樣才能得到結構體名稱(MyApp.MyModel
在我的情況)?
讓我說我有一個結構,struct = %MyApp.MyModel{ filled_with_data: "true }
。如何在elixir中獲取struct name?
我怎樣才能得到結構體名稱(MyApp.MyModel
在我的情況)?
它存儲在一個名爲__struct__
的域中,所以struct.__struct__ == MyApp.MyModel
。
「仙丹」。前綴,但保持你的任何模塊的前綴,你可以這樣做:
name = your_map.__struct__
|> Module.split
|> Enum.join(".")
哦,市,我認爲這是一個悲慘的方式... – asiniy