Class: Uses::MethodName
- Inherits:
-
Object
- Object
- Uses::MethodName
- Defined in:
- lib/uses/method_name.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(uses_method_args) ⇒ MethodName
constructor
A new instance of MethodName.
- #to_s ⇒ Object
Constructor Details
#initialize(uses_method_args) ⇒ MethodName
Returns a new instance of MethodName.
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/uses/method_name.rb', line 9 def initialize(uses_method_args) @name = if uses_method_args.method_name_override.nil? self.class.derive_method_name(uses_method_args.klass_being_used) else uses_method_args.method_name_override.to_s end if @name !~ /^[a-z0-9_]+$/ raise Uses::InvalidMethodName.new("Cannot determine a default name for #{uses_method_args.klass_being_used} used by #{uses_method_args.klass_with_uses}. Use as: to specify the name") end end |
Class Method Details
.derive_method_name(klass) ⇒ Object
5 6 7 |
# File 'lib/uses/method_name.rb', line 5 def self.derive_method_name(klass) klass.name.to_s.underscore.gsub(/\//,"_") end |
Instance Method Details
#to_s ⇒ Object
19 20 21 |
# File 'lib/uses/method_name.rb', line 19 def to_s @name end |