Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there a way to form the "full" string representation of a instance? #7

Open
DavidSagan opened this issue Sep 4, 2024 · 1 comment

Comments

@DavidSagan
Copy link

For example:

julia> using EnumX

julia> @enumx Fruit Apple Banana

julia> x = Fruit.Apple

julia> string(x)
"Apple"

The string does not include the scope. I would like a way to get the string representation with the scope prefixed which for this example would be "Fruit.Apple". Is there a way to do this?

@g-gundam
Copy link

g-gundam commented Dec 5, 2024

@DavidSagan - This is going to be kinda ugly, but maybe someone who knows Julia better can chime in.

julia> @enumx Fruit Apple Banana

julia> function Base.print(io::IO, f::Fruit.T)
           n = Dict(Fruit.Apple => "Apple", Fruit.Banana => "Banana")
           s = "Fruit.$(n[f])"
           write(io, s)
       end

julia> string(Fruit.Apple)
"Fruit.Apple"

julia> string(Fruit.Banana)
"Fruit.Banana"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants