Module: Glossarist::Utilities::CommonFunctions
- Included in:
- ConceptSource, Designation::GrammarInfo, ManagedConcept
- Defined in:
- lib/glossarist/utilities/common_functions.rb
Instance Method Summary collapse
-
#slice_keys(hash, keys) ⇒ Object
Hash#slice is not available in Ruby 2.4 so we have to do this ourselves :( slice hash keys.
-
#symbolize_keys(hash) ⇒ Object
Hash#transform_keys is not available in Ruby 2.4 so we have to do this ourselves :( symbolize hash keys.
Instance Method Details
#slice_keys(hash, keys) ⇒ Object
Hash#slice is not available in Ruby 2.4 so we have to do this ourselves :( slice hash keys
20 21 22 23 24 25 26 |
# File 'lib/glossarist/utilities/common_functions.rb', line 20 def slice_keys(hash, keys) result = {} keys.each do |key| result[key] = hash[key] if hash.key?(key) end result end |
#symbolize_keys(hash) ⇒ Object
Hash#transform_keys is not available in Ruby 2.4 so we have to do this ourselves :( symbolize hash keys
9 10 11 12 13 14 15 |
# File 'lib/glossarist/utilities/common_functions.rb', line 9 def symbolize_keys(hash) result = {} hash.each_pair do |key, value| result[key.to_sym] = value end result end |