Tbpgr Blog

Employee Experience Engineer tbpgr(てぃーびー) のブログ

Ruby | Regexp | == / eql?

概要

Regexp#self == other -> bool
Regexp#eql?(other) -> bool

詳細

otherが同じパターン、オプション、文字コード正規表現であったらtrueを返却。

サンプルコード
require 'tbpgr_utils'


bulk_puts_eval binding, <<-EOS
/h.ge/ == /h.ge/
/h.ge/ == Regexp.compile(/h.ge/)
/h.ge/ == /h.ge/i
/(?-mix:hoge)|(?-mix:hige)/ == Regexp.union(/hoge/, /hige/)
EOS

__END__
下記はTbpgrUtils gemの機能
bulk_puts_eval

https://rubygems.org/gems/tbpgr_utils
https://github.com/tbpgr/tbpgr_utils

出力

/h.ge/ == /h.ge/                                            # => true
/h.ge/ == Regexp.compile(/h.ge/)                            # => true
/h.ge/ == /h.ge/i                                           # => false
/(?-mix:hoge)|(?-mix:hige)/ == Regexp.union(/hoge/, /hige/) # => true