aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel
diff options
context:
space:
mode:
authorBart <bartdewater@gmail.com>2018-07-29 13:58:35 -0400
committerKasper Timm Hansen <kaspth@gmail.com>2018-07-29 19:58:35 +0200
commiteb4f7cad2087ea9365da36938784bcb80696a9d8 (patch)
treefd25c428f5aee110d2eff4deb36093aa8b24b11c /activemodel
parent66da5ea1286c2a3b428a18546f7f076722218bd4 (diff)
downloadrails-eb4f7cad2087ea9365da36938784bcb80696a9d8.tar.gz
rails-eb4f7cad2087ea9365da36938784bcb80696a9d8.tar.bz2
rails-eb4f7cad2087ea9365da36938784bcb80696a9d8.zip
ActiveModel::Naming delegate match? in the same manner as =~ and != (#33466)
The purpose of the module seems to quack like a string.
Diffstat (limited to 'activemodel')
-rw-r--r--activemodel/lib/active_model/naming.rb18
1 files changed, 17 insertions, 1 deletions
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
@@ -111,6 +111,22 @@ module ActiveModel
# BlogPost.model_name.eql?('Blog Post') # => false
##
+ # :method: match?
+ #
+ # :call-seq:
+ # match?(regexp)
+ #
+ # Equivalent to <tt>String#match?</tt>. 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
#
# :call-seq:
@@ -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+