-
Notifications
You must be signed in to change notification settings - Fork 13
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
Enums #62
base: master
Are you sure you want to change the base?
Enums #62
Conversation
lib/elftools/enums.rb
Outdated
attr_reader :values | ||
end | ||
|
||
def initialize(attrs = 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm confused about the name - shouldn't "attrs" be "value"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add description about the parameter, seems it can be an integer or a symbol
class Relocation32 < Enum | ||
exclusive true | ||
enum_attr :none, 0 | ||
enum_attr :"32", 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like these integer names but.. sigh
Allow usages: ``` Bind::LOCAL Bind.LOCAL Bind[:local] ``` Allow comparisons: ``` b == 0 b == 'local' b == :local b == Bind::LOCAL ```
end | ||
|
||
class << self | ||
attr_reader :values |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add document of its type
class << self | ||
attr_reader :values | ||
|
||
def val(value) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add document
def val(value) | ||
key = if value.is_a? self.class | ||
value.to_i | ||
elsif values.keys.include?(value) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
keys.include? can be replaced with "key?"
|
||
def inspect | ||
v = self.class.values[@value] | ||
v ? "#{self.class.name}.#{v.upcase}" : @value |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unsure whether it matters - shouldn't "@value" be "@value.inspect"?
Any update here :) ? |
yes? |
Sorry, will do, got small setback and had little time
…On Sat, Jul 24, 2021, 16:37 david942j ***@***.***> wrote:
yes?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#62 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABWONCR3HU6UTDXWRFZCNQ3TZLFZ3ANCNFSM44FXJORQ>
.
|
I do not consider this part of code perfect, yet this is what I came up with to manage elf types more easily.
I think constants should be accessed with Class::CONSTANT, eg.
Visibility::NONE
, yet these enums currently work only withVisibility.NONE
. I did not fix it, I was short on time. I also don't see clear solution.What I wanted from these enums:
puts symbol.st_vis
to printNone
instead of ... 42 or whatever.symbol.st_vis + 2
to be 44 (or whatever) instead of "None2", currently may require casting with.to_i
symbol.st_vis = :none
, dunno if worksPart of #52