summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDaniele Alessandri <suppakilla@gmail.com>2010-07-18 21:00:27 +0800
committerMarco Ceresa <ceresa@gmail.com>2010-07-18 21:31:53 +0800
commite1b6823b7c8daf5a6742ab41cc9bdc585c994bf8 (patch)
tree8be0b26082e510bc3d9ad0ff48451986464d0141 /lib
parentbea4380c30668c9ea0649c5eb2ef2c0ad61096ee (diff)
downloadipaddress-e1b6823b7c8daf5a6742ab41cc9bdc585c994bf8.tar.gz
Create an Hash#key alias for Hash#index (Ruby < 1.9)
Diffstat (limited to 'lib')
-rw-r--r--lib/ipaddress/extensions/extensions.rb6
1 files changed, 6 insertions, 0 deletions
diff --git a/lib/ipaddress/extensions/extensions.rb b/lib/ipaddress/extensions/extensions.rb
index 0d70bda..a474e18 100644
--- a/lib/ipaddress/extensions/extensions.rb
+++ b/lib/ipaddress/extensions/extensions.rb
@@ -2,6 +2,12 @@ class << Math
def log2(n); log(n) / log(2); end
end
+if RUBY_VERSION =~ /1\.8/
+ class Hash
+ alias :key :index
+ end
+end
+
class Integer
def power_of_2?
Math::log2(self).to_i == Math::log2(self)