I'm in the very beginning of learning Elixir, but have a programming background with several OOP languages, mostly Ruby. I found example how I can define struct inside module:
defmodule Example.User do
defstruct name: "Sean", roles: []
end
Also, I found I can set this value when I create structs:
steve = %Example.User{name: "Steve", roles: [:admin, :owner]}
and can access it outside module just by calling steve.name
The question is, how can I access struct data INSIDE module, so let's say I want to access name field from call_my_name function:
defmodule Example.User do
defstruct name: ""
def call_my_name do
IO.write(???)
end
end
martin = %Example.User{name: "Martin"}
In terms of OOP, I just trying to write a getter.
How can I do it? What is a good/default way to do it? If I can't, why?