Use upper camel case for method steps

  • Name a method step's method in upper camel case (e.g. AssertValidAmount), not the snake_case used for regular Ruby methods.

  • This makes it visually obvious, at a glance, which private methods are steps versus ordinary helpers.

    class ParseAmount
      include ConvenientService::Standard::Config
    
      attr_reader :raw_amount
    
      step :AssertValidAmount,
        in: :raw_amount
    
      step :result,
        in: :raw_amount,
        out: :cents
    
      def initialize(raw_amount:)
        @raw_amount = raw_amount
      end
    
      def result
        success(cents: to_cents)
      end
    
      private
    
      def AssertValidAmount
        return failure("Amount `#{raw_amount}` is not a valid positive number") unless raw_amount.to_s.match?(/\A\d+(\.\d{1,2})?\z/)
    
        success
      end
    
      def to_cents
        (raw_amount.to_f * 100).round
      end
    end

    AssertValidAmount is a method step (upper camel case, declared via step :AssertValidAmount above). to_cents is a regular private helper (snake_case, called directly from result). Just by looking at a method's name, you know which one it is.

See also

Sources