Skip to content

Commit

Permalink
Better: Add ruby 3.1 compatibility.
Browse files Browse the repository at this point in the history
  • Loading branch information
ylecuyer authored and joshuacronemeyer committed Aug 10, 2023
1 parent 0ad9c66 commit e3b4c9f
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions lib/timecop/time_extensions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,24 @@ def mock_time

alias_method :now_without_mock_time, :now

def now_with_mock_time
mock_time || now_without_mock_time
def now_with_mock_time(*args)
mock_time || now_without_mock_time(*args)
end

alias_method :now, :now_with_mock_time

alias_method :new_without_mock_time, :new

def new_with_mock_time(*args)
args.size <= 0 ? now : new_without_mock_time(*args)
def new_with_mock_time(*args, **kwargs)
if args.size <= 0
now(*args)
else
if kwargs == {}
new_without_mock_time(*args)
else
new_without_mock_time(*args, **kwargs)
end
end
end

ruby2_keywords :new_with_mock_time if Module.private_method_defined?(:ruby2_keywords)
Expand Down

0 comments on commit e3b4c9f

Please sign in to comment.