From eb4f7cad2087ea9365da36938784bcb80696a9d8 Mon Sep 17 00:00:00 2001 From: Bart Date: Sun, 29 Jul 2018 13:58:35 -0400 Subject: ActiveModel::Naming delegate match? in the same manner as =~ and != (#33466) The purpose of the module seems to quack like a string. --- activemodel/lib/active_model/naming.rb | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'activemodel/lib') diff --git a/activemodel/lib/active_model/naming.rb b/activemodel/lib/active_model/naming.rb index dfccd03cd8..983401801f 100644 --- a/activemodel/lib/active_model/naming.rb +++ b/activemodel/lib/active_model/naming.rb @@ -110,6 +110,22 @@ module ActiveModel # BlogPost.model_name.eql?('BlogPost') # => true # BlogPost.model_name.eql?('Blog Post') # => false + ## + # :method: match? + # + # :call-seq: + # match?(regexp) + # + # Equivalent to String#match?. Match the class name against the + # given regexp. Returns +true+ if there is a match, otherwise +false+. + # + # class BlogPost + # extend ActiveModel::Naming + # end + # + # BlogPost.model_name.match?(/Post/) # => true + # BlogPost.model_name.match?(/\d/) # => false + ## # :method: to_s # @@ -131,7 +147,7 @@ module ActiveModel # to_str() # # Equivalent to +to_s+. - delegate :==, :===, :<=>, :=~, :"!~", :eql?, :to_s, + delegate :==, :===, :<=>, :=~, :"!~", :eql?, :match?, :to_s, :to_str, :as_json, to: :name # Returns a new ActiveModel::Name instance. By default, the +namespace+ -- cgit v1.2.3