Class: Cans::Address
- Inherits:
-
Object
- Object
- Cans::Address
- Defined in:
- lib/cans/address.rb
Constant Summary collapse
- METHOD_KIND_REGEX =
%r{\.(.)}
- MODULE_NAME_REGEX =
/^(.+)\/\.|^(.+)$/
- METHOD_NAME_REGEX =
%r{\../(.+)$}
Instance Method Summary collapse
-
#initialize(address_string) ⇒ Address
constructor
A new instance of Address.
- #method_kind ⇒ Object
- #method_name ⇒ Object
- #module_name ⇒ Object
- #target_method ⇒ Object
- #target_module ⇒ Object
Constructor Details
#initialize(address_string) ⇒ Address
Returns a new instance of Address.
7 8 9 |
# File 'lib/cans/address.rb', line 7 def initialize(address_string) @string = address_string end |
Instance Method Details
#method_kind ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/cans/address.rb', line 17 def method_kind md = METHOD_KIND_REGEX.match @string raise "No method_kind found" unless md return case md[1] when 'i' :instance when 'm' :module else raise 'Unexpected method_kind found' end end |
#method_name ⇒ Object
30 31 32 33 34 |
# File 'lib/cans/address.rb', line 30 def method_name md = METHOD_NAME_REGEX.match @string raise 'No method_name found' unless md return md[1].gsub('/','') end |
#module_name ⇒ Object
11 12 13 14 15 |
# File 'lib/cans/address.rb', line 11 def module_name md = MODULE_NAME_REGEX.match @string raise "No module_name found in #{@string.inspect}" unless md return md.captures.detect{ |m| !(m.nil? || m.empty?) }.gsub('/','::') end |
#target_method ⇒ Object
40 41 42 43 44 45 46 47 |
# File 'lib/cans/address.rb', line 40 def target_method case method_kind when :instance target_module.instance_method method_name when :module target_module.method method_name end end |
#target_module ⇒ Object
36 37 38 |
# File 'lib/cans/address.rb', line 36 def target_module eval "::#{module_name}" end |