=~

=~(regexp)
Instance Public methods

Equivalent to String#=~. Match the class name against the given regexp. Returns the position where the match starts or nil if there is no match.

1
2
3
4
5
6
class BlogPost
  extend ActiveModel::Naming
end
 
BlogPost.model_name =~ /Post/ # => 4
BlogPost.model_name =~ /\d/   # => nil
doc_ruby_on_rails
2025-01-10 15:47:30
Comments
Leave a Comment

Please login to continue.