Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Monkey patch for speedup date/time parsing
class Date
module Format
class Bag
A_FIELDS = %w{year mon mday hour min sec sec_fraction offset zone wday}
for fld in A_FIELDS + %w{_comp}
attr_accessor fld.to_sym
end
to_hash = A_FIELDS.map{|fld| "res[:#{fld}] = @#{fld} unless @#{fld}.nil?"}.join("\n")
class_eval <<-"END"
def to_hash
res = @elem.empty? ? {} : @elem.reject{|k,v| /\A_/ =~ k.to_s || v.nil? }
#{to_hash}
res
end
END
end
end
end
@funny-falcon

This comment has been minimized.

Copy link
Owner Author

funny-falcon commented Mar 15, 2011

It seems that it is not need for ruby 1.9.3 (future versions). But it will help with <=1.9.2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.