Skip to content
This repository has been archived by the owner on Jun 24, 2022. It is now read-only.

allocator undefined for Date #21

Closed
jstorimer opened this issue Feb 28, 2011 · 7 comments
Closed

allocator undefined for Date #21

jstorimer opened this issue Feb 28, 2011 · 7 comments

Comments

@jstorimer
Copy link

Tried this with home_run (1.0.0) and ActiveSupport (3.0.4 and 3.0.5)

>> require 'active_support/all'
=> true
>> date = Date.new
=> Mon, 01 Jan -4712
>> date.dup
=> Mon, 01 Jan -4712
>> require 'home_run'
=> true
>> date = Date.new
=> #<Date -4713-11-24>
>> date.dup
TypeError: allocator undefined for Date
  from (irb):8:in `dup'
  from (irb):8
@jeremyevans
Copy link
Owner

From the README:

All public class and instance methods for both Date and DateTime are implemented, except that the allocate class method is not available and on 1.9, _dump and _load are used instead of marshal_dump and marshal_load. 

@jeremyevans
Copy link
Owner

Oops, I should read the code before just looking at the error message. Looks like I need to add a dup and possibly clone method since ruby won't take care of this automatically.

@alindeman
Copy link

Adding #dup would be excellent; otherwise, home_run is not really usable in Rails 3.0.5.

@alindeman
Copy link

In the mean time, this monkey patch will get the job done (could drop it in config/initializers for a Rails app).

class Date
  def dup
    self + 0
  end
end

@jeremyevans
Copy link
Owner

That should work for dup, but won't work for clone. I hope to put out a new gem release later today that should fix dup, clone, and allocate, I'm testing the changes now.

@alindeman
Copy link

Thanks! I was just putting what I think is the minimal code to get it working with Rails 3.0.5.

@jeremyevans
Copy link
Owner

This should be fixed by:

https://github.com/jeremyevans/home_run/commit/a0afad36b86d33a6022ff20ee0602e9395b6da06
https://github.com/jeremyevans/home_run/commit/ba9a86ff668615d0b619b69ff861f4e740c6865a

The changes should work for all supported ruby implementations, except that DateTime#{dup,clone} cause SystemStackErrors on JRuby due to a bug in JRuby's cext support.

Thanks for filing the issue. 1.0.1 gems have been released with those changes and a small fix for #step.

This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants