Sha256: bfddb24b4229a426e351c6ef643a9d2ebc8caf9b32314d1fcb8cf5be2fab3216

Contents?: true

Size: 388 Bytes

Versions: 8

Compression:

Stored size: 388 Bytes

Contents

# frozen_string_literal: true

module ActionPolicy
  module Ext
    # Add underscore to String
    module StringUnderscore
      refine String do
        def underscore
          word = gsub("::", "/")
          word.gsub!(/([A-Z\d]+)([A-Z][a-z])/, '\1_\2')
          word.gsub!(/([a-z\d])([A-Z])/, '\1_\2')
          word.downcase!
          word
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
action_policy-0.7.3 lib/action_policy/ext/string_underscore.rb
action_policy-0.7.2 lib/action_policy/ext/string_underscore.rb
action_policy-0.7.1 lib/action_policy/ext/string_underscore.rb
action_policy-0.7.0 lib/action_policy/ext/string_underscore.rb
action_policy-0.6.9 lib/action_policy/ext/string_underscore.rb
action_policy-0.6.8 lib/action_policy/ext/string_underscore.rb
action_policy-0.6.7 lib/action_policy/ext/string_underscore.rb
action_policy-0.6.6 lib/action_policy/ext/string_underscore.rb