Class: Protod::RubyIdent
- Inherits:
-
Object
- Object
- Protod::RubyIdent
- Includes:
- ActiveModel::Attributes, ActiveModel::Model
- Defined in:
- lib/protod/ruby_ident.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.absolute_of(ruby_ident) ⇒ Object
30 31 32 33 34 |
# File 'lib/protod/ruby_ident.rb', line 30 def absolute_of(ruby_ident) return if ruby_ident.blank? "::#{ruby_ident.to_s.delete_prefix('::')}" end |
.build_from(string) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/protod/ruby_ident.rb', line 11 def build_from(string) return if string.blank? string = string.gsub('__', '::') const_name, method_name, singleton = case when string.include?('.') [*string.split('.'), true] when string.include?('#') [*string.split('#'), false] else [string, nil, false] end return unless const_name.safe_constantize new(const_name: const_name, method_name: method_name, singleton: singleton) end |
Instance Method Details
#==(other) ⇒ Object
41 42 43 |
# File 'lib/protod/ruby_ident.rb', line 41 def ==(other) to_s == other.to_s end |
#const_name ⇒ Object
37 38 39 |
# File 'lib/protod/ruby_ident.rb', line 37 def const_name self.class.absolute_of(super) end |
#to_s ⇒ Object
45 46 47 |
# File 'lib/protod/ruby_ident.rb', line 45 def to_s [const_name, method_name].compact.join(singleton ? '.' : '#') end |