Class: DiverDown::Definition::MethodId
- Inherits:
-
Object
- Object
- DiverDown::Definition::MethodId
- Includes:
- Comparable
- Defined in:
- lib/diver_down/definition/method_id.rb
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#paths ⇒ Object
readonly
Returns the value of attribute paths.
Class Method Summary collapse
Instance Method Summary collapse
- #<=>(other) ⇒ Integer
- #==(other) ⇒ Boolean (also: #eq?, #eql?)
- #add_path(*paths) ⇒ Object
- #freeze ⇒ void
- #hash ⇒ Integer
- #human_method_name ⇒ String
-
#initialize(name:, context:, paths: Set.new) ⇒ MethodId
constructor
A new instance of MethodId.
- #inspect ⇒ String
- #to_h ⇒ Hash
Constructor Details
#initialize(name:, context:, paths: Set.new) ⇒ MethodId
Returns a new instance of MethodId.
25 26 27 28 29 30 31 |
# File 'lib/diver_down/definition/method_id.rb', line 25 def initialize(name:, context:, paths: Set.new) raise ArgumentError, "invalid context: #{context}" unless VALID_CONTEXT.include?(context) @name = name.to_s @context = context.to_s @paths = paths.to_set end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
11 12 13 |
# File 'lib/diver_down/definition/method_id.rb', line 11 def context @context end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
11 12 13 |
# File 'lib/diver_down/definition/method_id.rb', line 11 def name @name end |
#paths ⇒ Object (readonly)
Returns the value of attribute paths.
11 12 13 |
# File 'lib/diver_down/definition/method_id.rb', line 11 def paths @paths end |
Class Method Details
.from_hash(hash) ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/diver_down/definition/method_id.rb', line 14 def self.from_hash(hash) new( name: hash[:name] || hash['name'], context: hash[:context] || hash['context'], paths: hash[:paths] || hash['paths'] || [] ) end |
Instance Method Details
#<=>(other) ⇒ Integer
62 63 64 |
# File 'lib/diver_down/definition/method_id.rb', line 62 def <=>(other) [context, name] <=> [other.context, other.name] end |
#==(other) ⇒ Boolean Also known as: eq?, eql?
68 69 70 71 72 73 |
# File 'lib/diver_down/definition/method_id.rb', line 68 def ==(other) other.is_a?(self.class) && name == other.name && context == other.context && paths == other.paths end |
#add_path(*paths) ⇒ Object
34 35 36 37 38 |
# File 'lib/diver_down/definition/method_id.rb', line 34 def add_path(*paths) paths.each do @paths.add(_1) end end |
#freeze ⇒ void
This method returns an undefined value.
83 84 85 86 |
# File 'lib/diver_down/definition/method_id.rb', line 83 def freeze super @paths.freeze end |
#hash ⇒ Integer
56 57 58 |
# File 'lib/diver_down/definition/method_id.rb', line 56 def hash [self.class, name, context, paths].hash end |
#human_method_name ⇒ String
41 42 43 44 |
# File 'lib/diver_down/definition/method_id.rb', line 41 def human_method_name prefix = context == 'instance' ? '#' : '.' "#{prefix}#{name}" end |
#inspect ⇒ String
78 79 80 |
# File 'lib/diver_down/definition/method_id.rb', line 78 def inspect %(#<#{self.class} #{human_method_name} paths=#{paths.inspect}>") end |
#to_h ⇒ Hash
47 48 49 50 51 52 53 |
# File 'lib/diver_down/definition/method_id.rb', line 47 def to_h { name:, context:, paths: @paths.sort, } end |