Skip to content

Commit

Permalink
Fix for Ruby 2.2 with custom offset
Browse files Browse the repository at this point in the history
Ruby 2.2.0 considers `epoch = epoch` a circular reference and ignores the variable assignment. Changing the argument assignment to `epoch_offset` for the function fixes the Ruby 2.
2.0 issues and specs.
  • Loading branch information
isaachall committed Apr 9, 2015
1 parent d3767f0 commit f0af6d2
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions druuid.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ class << self
# @param [Time] time of UUID
# @param [Numeric] epoch offset
# @return [Bignum] UUID
def gen time = Time.now, epoch = epoch
ms = ((time.to_f - epoch.to_i) * 1e3).round
def gen time = Time.now, epoch_offset = epoch
ms = ((time.to_f - epoch_offset.to_i) * 1e3).round
rand = (SecureRandom.random_number * 1e16).round
id = ms << (64 - 41)
id | rand % (2 ** (64 - 41))
Expand All @@ -33,9 +33,9 @@ def gen time = Time.now, epoch = epoch
# @example
# Druuid.time 11142943683383068069
# # => 2012-02-04 00:00:00 -0800
def time uuid, epoch = epoch
def time uuid, epoch_offset = epoch
ms = uuid >> (64 - 41)
Time.at (ms / 1e3) + epoch.to_i
Time.at (ms / 1e3) + epoch_offset.to_i
end

end
Expand Down

0 comments on commit f0af6d2

Please sign in to comment.