Class: SystemNavigation::MethodHash

Inherits:
Hash
  • Object
show all
Defined in:
lib/system_navigation/method_hash.rb

Overview

Since:

  • 0.1.0

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(based_on: nil, include_super: nil) ⇒ MethodHash

Returns a new instance of MethodHash.

Since:

  • 0.1.0



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/system_navigation/method_hash.rb', line 8

def initialize(based_on: nil, include_super: nil)
  @hash = super()

  if based_on
    @hash.merge!({
      public: {
        instance: based_on.public_instance_methods(include_super),
        singleton: based_on.singleton_class.public_instance_methods(include_super)
      },
      private: {
        instance: based_on.private_instance_methods(include_super),
        singleton: based_on.singleton_class.private_instance_methods(include_super)
      },
      protected: {
        instance: based_on.protected_instance_methods(include_super),
        singleton: based_on.singleton_class.protected_instance_methods(include_super)
      }
    })
  else
    @hash.merge!(empty_hash)
  end
end

Class Method Details

.create(**args) ⇒ Object

Since:

  • 0.1.0



3
4
5
# File 'lib/system_navigation/method_hash.rb', line 3

def self.create(**args)
  self.new(args)
end

Instance Method Details

#as_arrayObject

Since:

  • 0.1.0



31
32
33
# File 'lib/system_navigation/method_hash.rb', line 31

def as_array
  self.values.map { |h| h[:instance] + h[:singleton] }.flatten.compact
end

#empty?Boolean

Returns:

  • (Boolean)

Since:

  • 0.1.0



35
36
37
# File 'lib/system_navigation/method_hash.rb', line 35

def empty?
  self == empty_hash
end