Skip to content

Commit

Permalink
Use magic comment to freeze strings in Ruby 2.3+.
Browse files Browse the repository at this point in the history
Include a fallback in `self.[]` for earlier Ruby versions.

refs GH-5
  • Loading branch information
xwmx committed Jun 23, 2016
1 parent aa48c4f commit bc799ce
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/iso-639.rb
@@ -1,10 +1,18 @@
# encoding: UTF-8
# frozen_string_literal: true
# http://www.loc.gov/standards/iso639-2/ascii_8bits.html

class ISO_639 < Array
# Redefine `[]` to freeze all strings and arrays.
#
# Ruby 2.3+ uses the `frozen_string_literal` magic comment to freeze all
# strings, while previous versions require the `#map` approach.
def self.[](*args)
super(*args.map(&:freeze)).freeze
if args[0].frozen?
super(*args).freeze
else
super(*args.map(&:freeze)).freeze
end
end

# The ISO 639-2 dataset as an array of entries. Each entry is an array with
Expand Down

0 comments on commit bc799ce

Please sign in to comment.