lib/core/common.rb in buildr-1.2.3 vs lib/core/common.rb in buildr-1.2.4

- old
+ new

@@ -17,11 +17,12 @@ # Hash.from_properties(str) # => { "foo"=>"bar", "baz"=>"fab" }.to_properties def from_java_properties(string) string.gsub(/\\\n/, "").split("\n").select { |line| line =~ /^[^#].*=.*/ }. map { |line| line.gsub(/\\[trnf\\]/) { |escaped| {?t=>"\t", ?r=>"\r", ?n=>"\n", ?f=>"\f", ?\\=>"\\"}[escaped[1]] } }. - inject({}) { |hash, line| name, value = line.split("=") ; hash[name] = value ; hash } + map { |line| line.split("=") }. + inject({}) { |hash, (name, value)| hash.merge(name=>value) } end end # :call-seq: @@ -29,25 +30,25 @@ # # Returns a new hash with only the specified keys. # # For example: # { :a=>1, :b=>2, :c=>3, :d=>4 }.only(:a, :c) - # => { :b=>2, :d=>4 } + # => { :a=>1, :c=>3 } def only(*keys) - self.inject({}) { |hash, pair| hash[pair[0]] = pair[1] if keys.include?(pair[0]) ; hash } + keys.inject({}) { |hash, key| has_key?(key) ? hash.merge(key=>self[key]) : hash } end # :call-seq: # except(keys*) => hash # # Returns a new hash without the specified keys. # # For example: # { :a=>1, :b=>2, :c=>3, :d=>4 }.except(:a, :c) - # => { :a=>1, :c=>3 } + # => { :b=>2, :d=>4 } def except(*keys) - self.inject({}) { |hash, pair| hash[pair[0]] = pair[1] unless keys.include?(pair[0]) ; hash } + (self.keys - keys).inject({}) { |hash, key| hash.merge(key=>self[key]) } end # :call-seq: # to_java_properties() => string #