lib/sass/util/ordered_hash.rb in sass-3.3.0.alpha.256 vs lib/sass/util/ordered_hash.rb in sass-3.3.0.alpha.353
- old
+ new
@@ -1,18 +1,18 @@
# Copyright (c) 2005-2013 David Heinemeier Hansson
-#
+#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
-#
+#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
-#
+#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
@@ -37,25 +37,25 @@
end
def self.[](*args)
ordered_hash = new
- if (args.length == 1 && args.first.is_a?(Array))
+ if args.length == 1 && args.first.is_a?(Array)
args.first.each do |key_value_pair|
- next unless (key_value_pair.is_a?(Array))
+ next unless key_value_pair.is_a?(Array)
ordered_hash[key_value_pair[0]] = key_value_pair[1]
end
return ordered_hash
end
- unless (args.size % 2 == 0)
+ unless args.size.even?
raise ArgumentError.new("odd number of arguments for Hash")
end
args.each_with_index do |val, ind|
- next if (ind % 2 != 0)
+ next if ind.odd?
ordered_hash[val] = args[ind + 1]
end
ordered_hash
end
@@ -98,30 +98,30 @@
def keys
@keys.dup
end
def values
- @keys.collect { |key| self[key] }
+ @keys.map {|key| self[key]}
end
def to_hash
self
end
def to_a
- @keys.map { |key| [ key, self[key] ] }
+ @keys.map {|key| [key, self[key]]}
end
def each_key
return to_enum(:each_key) unless block_given?
- @keys.each { |key| yield key }
+ @keys.each {|key| yield key}
self
end
def each_value
return to_enum(:each_value) unless block_given?
- @keys.each { |key| yield self[key]}
+ @keys.each {|key| yield self[key]}
self
end
def each
return to_enum(:each) unless block_given?
@@ -149,38 +149,40 @@
[k, v]
end
def merge!(other_hash)
if block_given?
- other_hash.each { |k, v| self[k] = key?(k) ? yield(k, self[k], v) : v }
+ other_hash.each {|k, v| self[k] = key?(k) ? yield(k, self[k], v) : v}
else
- other_hash.each { |k, v| self[k] = v }
+ other_hash.each {|k, v| self[k] = v}
end
self
end
alias_method :update, :merge!
def merge(other_hash, &block)
dup.merge!(other_hash, &block)
end
- # When replacing with another hash, the initial order of our keys must come from the other hash -ordered or not.
+ # When replacing with another hash, the initial order of our keys must come from the other hash --
+ # ordered or not.
def replace(other)
super
@keys = other.keys
self
end
def invert
- OrderedHash[self.to_a.map!{|key_value_pair| key_value_pair.reverse}]
+ OrderedHash[to_a.map! {|key_value_pair| key_value_pair.reverse}]
end
def inspect
"#<OrderedHash #{super}>"
end
private
- def sync_keys!
- @keys.delete_if {|k| !has_key?(k)}
- end
+
+ def sync_keys!
+ @keys.delete_if {|k| !has_key?(k)}
+ end
end