Sha256: 4656ee73283648424bb38e0ea525b2d691858c867fafd2d63c8877157dfffff9

Contents?: true

Size: 771 Bytes

Versions: 14

Compression:

Stored size: 771 Bytes

Contents

class Array
  #inspired by: http://thepugautomatic.com/2014/11/array-to-proc-for-hash-access/
  def to_proc
    ->(hash_or_object) {
      if hash_or_object.is_a?(::Hash)
        length == 1 ? hash_or_object[first] : hash_or_object.values_at(*self)
      else
        length == 1 ? hash_or_object.__send__(first) : self.each_with_object({}){ |method_name,result|
                                                         result[method_name] = hash_or_object.__send__(method_name)
                                                       }
      end
    }
  end

  def flat_compact_uniq!
    self.flatten!
    self.compact!
    self.uniq!
    self
  end
  alias :flatten_compact_uniq! :flat_compact_uniq!

  def to_single_quoted_list
    "\'#{self.join("', '")}\'"
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
trax_core-0.0.86 lib/trax/core/ext/array.rb
trax_core-0.0.85 lib/trax/core/ext/array.rb
trax_core-0.0.84 lib/trax/core/ext/array.rb
trax_core-0.0.83 lib/trax/core/ext/array.rb
trax_core-0.0.82 lib/trax/core/ext/array.rb
trax_core-0.0.81 lib/trax/core/ext/array.rb
trax_core-0.0.80 lib/trax/core/ext/array.rb
trax_core-0.0.79 lib/trax/core/ext/array.rb
trax_core-0.0.78 lib/trax/core/ext/array.rb
trax_core-0.0.77 lib/trax/core/ext/array.rb
trax_core-0.0.76 lib/trax/core/ext/array.rb
trax_core-0.0.74 lib/trax/core/ext/array.rb
trax_core-0.0.73 lib/trax/core/ext/array.rb
trax_core-0.0.72 lib/trax/core/ext/array.rb