judofyr / temple

Template compilation framework in Ruby
http://judofyr.net/posts/temple.html
MIT License
491 stars 53 forks source link

Suppress deprecated warning by Object#=~ since ruby 2.6 #129

Closed unasuke closed 4 years ago

unasuke commented 4 years ago

In Temple::Mixins::GrammerDSL::Value#Rule, call =~ method to Class class then that causes a warning message. This behavior introduced from ruby 2.6 with -W option. (And ruby 2.7 always show a warning message)

https://bugs.ruby-lang.org/issues/15231 https://github.com/ruby/ruby/commit/ebff9dc10

~Therefore if "elem" is Class class, skip calling =~ method.~ Therefore use case-when-else clause to avoid warning.

judofyr commented 4 years ago

I'm not well-versed in this code to be honest. Does this variant work as well?

case elem
when Class
  …
when /…/
  …
end

That would read better to me.

unasuke commented 4 years ago

@judofyr It seems better than my patch. Thanks! If use case-when clause, it doesn't call =~ method, use === method internally. So when Class clause is unneeded I thought.