diff options
author | Eric Wong <e@80x24.org> | 2017-03-02 04:08:23 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2017-03-02 04:08:43 +0000 |
commit | f4c2ac4825f99ec4af529d65ae98abfaf034fb0f (patch) | |
tree | bbae58219dc4d158c033b892e0a7da67a969ecdc /lib/dtas.rb | |
parent | c2e04a5715d4cfa2b42fa09ba1f641d3ce741685 (diff) | |
download | dtas-f4c2ac4825f99ec4af529d65ae98abfaf034fb0f.tar.gz |
This is faster than relying on eval() for older Rubies. https://bugs.ruby-lang.org/issues/13077 Ruby 2.5 is targetted for release in December 2017.
Diffstat (limited to 'lib/dtas.rb')
-rw-r--r-- | lib/dtas.rb | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/lib/dtas.rb b/lib/dtas.rb index 1a1a882..ac416d7 100644 --- a/lib/dtas.rb +++ b/lib/dtas.rb @@ -24,6 +24,19 @@ module DTAS def self.null # :nodoc: @null ||= File.open('/dev/null', 'r+') end + + # String#-@ will deduplicate strings when Ruby 2.5 is released (Dec 2017) + # https://bugs.ruby-lang.org/issues/13077 + if RUBY_VERSION.to_f >= 2.5 + def self.dedupe_str(str) + -str + end + else + # Ruby 2.1 - 2.4, noop for older Rubies + def self.dedupe_str(str) + eval "#{str.inspect}.freeze" + end + end # :startdoc: end |