Comments (3)
Hi,
What is your version of Rails/ActiveSupport? What exactly doesn't print correctly? Please let me know how I could to reproduce the issue.
Michael
from awesome_print.
Hi Michael, I'm using Rails 3.1.3. On my machine, with awesome_print turned on:
(main):0 > Date.new
#<Date:0x7fc6316e0ee8
@__ca__ = {},
@of = 0,
@sg = 2299161,
attr_reader :ajd = -0.5
>
(main):0 > Date.new.inspect
"Mon, 01 Jan -4712"
(main):0 > Time.new
2011-12-02 13:43:02 -0200 # greenish
(main):0 > Time.new.inspect
"2011-12-02 13:43:31 -0200"
(main):0 > ActiveSupport::TimeZone.new('Eastern Time (US & Canada)').now
Fri, 02 Dec 2011 10:39:37 EST -05:00 #greenish
(main):0 > ActiveSupport::TimeZone.new('Eastern Time (US & Canada)').now.inspect
"Fri, 02 Dec 2011 10:44:02 EST -05:00"
I made this monkey-patch and it worked as expected afterwards:
module AwesomePrint
module TimeClasses
def self.included(base)
base.send :alias_method, :cast_without_time_classes, :cast
base.send :alias_method, :cast, :cast_with_time_classes
end
def cast_with_time_classes(object,type)
cast = cast_without_time_classes(object,type)
if object.is_a?(::Date)
cast = :date
end
cast
end
def awesome_date(object)
colorize(object.inspect, :time)
end
end
end
AwesomePrint::Formatter.send(:include,AwesomePrint::TimeClasses)
Hope that helped
from awesome_print.
Thanks! Looks like the latest ActiveSupport sticks in instance vars into the Date object so the date gets formatted as an object. Changing:
17: if object.is_a?(::ActiveSupport::TimeWithZone)
to
17: if object.is_a?(::ActiveSupport::TimeWithZone) || object.is_a?(::Date)
in ext/active_support.rb seems to fix it. I'm going to add a spec and make it part of 1.0.2 release.
Thanks again ;-)
Michael
from awesome_print.
Related Issues (20)
- new lines HOT 1
- Proc.new is deprecated HOT 5
- irb: ArgumentError (wrong number of arguments (given 1, expected 0)) HOT 2
- Output of non-empty Hash object fails when using Ruby 3.0 HOT 1
- 1.9 release HOT 12
- Array#uniq is not working on pry with `AwesomePrint.pry!` HOT 5
- Ruby 2.7.0 compatibility HOT 2
- problem with rails and ruby 3.0.0 HOT 2
- ArgumentError (wrong number of arguments (given 1, expected 0)) HOT 4
- undefined method `marshal_dump` for `ActiveModel::Errors` HOT 6
- Getting FrozenError (can't modify frozen String: "false") after upgrading to Ruby 2.7.3 using awesome_print (1.9.2) HOT 5
- Plain Ruby Objects are not formatted properly HOT 2
- Hi, can I put `.aprc` under ~/.config/awesome_print/aprc?
- `.pry!` does nothing in rails console
- Don't override/monkey patch `String` class HOT 3
- Provide a way of specifying custom formatting on user-created classes/objects HOT 2
- object_id option not operating as expected
- Maintained fork: amazing-print/amazing_print
- Pretty print object as executable code
- ap.awesome_sequel_dataset(ds) Arguments Error
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from awesome_print.