Class: Pwnlib::Constants::Constant
- Inherits:
-
Numeric
- Object
- Numeric
- Pwnlib::Constants::Constant
show all
- Defined in:
- lib/pwnlib/constants/constant.rb
Overview
A class that includes name and value representing a constant. This class works like an integer, and support operations with integers.
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(str, val) ⇒ Constant
Returns a new instance of Constant.
25
26
27
28
29
|
# File 'lib/pwnlib/constants/constant.rb', line 25
def initialize(str, val)
super()
@str = str
@val = val
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
We don’t need to fall back to super for this, so just disable the lint.
32
33
34
|
# File 'lib/pwnlib/constants/constant.rb', line 32
def method_missing(method, *args, &block)
@val.__send__(method, *args, &block)
end
|
Instance Attribute Details
#str ⇒ String
18
19
20
|
# File 'lib/pwnlib/constants/constant.rb', line 18
def str
@str
end
|
#val ⇒ Integer
21
22
23
|
# File 'lib/pwnlib/constants/constant.rb', line 21
def val
@val
end
|
Instance Method Details
#<=>(other) ⇒ Object
56
57
58
|
# File 'lib/pwnlib/constants/constant.rb', line 56
def <=>(other)
to_i <=> other.to_i
end
|
#coerce(other) ⇒ Object
40
41
42
|
# File 'lib/pwnlib/constants/constant.rb', line 40
def coerce(other)
[other.to_i, to_i]
end
|
#inspect ⇒ Object
52
53
54
|
# File 'lib/pwnlib/constants/constant.rb', line 52
def inspect
format('Constant(%p, %s)', @str, ::Pwnlib::Util::Fiddling.hex(@val))
end
|
#respond_to_missing?(method, include_all) ⇒ Boolean
36
37
38
|
# File 'lib/pwnlib/constants/constant.rb', line 36
def respond_to_missing?(method, include_all)
@val.respond_to?(method, include_all)
end
|
#to_i ⇒ Object
44
45
46
|
# File 'lib/pwnlib/constants/constant.rb', line 44
def to_i
@val
end
|
#to_s ⇒ Object
48
49
50
|
# File 'lib/pwnlib/constants/constant.rb', line 48
def to_s
@str
end
|