-
Notifications
You must be signed in to change notification settings - Fork 43
Shortcuts and formatters
zverok edited this page Apr 9, 2016
·
6 revisions
There are several things that are not required by require "reality"
(but
are included in interactive console).
Pretty inspect: require "reality/pretty_inspect"
redefines #inspect
method for some Ruby core classes, which are heavily utilized by reality, and
their default #inspect
is not that pretty. For example:
# without pretty_inspect
Reality::Entity('Yukihiro Matsumoto').birthday
# => #<Date: 1965-04-14 ((2438865j,0s,0n),+0s,2299161j)>
# with pretty_inspect
Reality::Entity('Yukihiro Matsumoto').birthday
# => #<Date: 1965-04-14>
# without pretty_inspect
Reality::Entity('Buenos Aires').population / Reality::Entity('London').population
# => (2890151/8416535)
# ↑ it's Rational, pretty precise, but hard to read
# with pretty_inspect
Reality::Entity('Buenos Aires').population / Reality::Entity('London').population
# => 0.3
# ↑ it's still the same Rational, but with less precise/more readable output
Shortcuts: require "reality/shortcuts"
provides you with pretty
concise syntax:
include Reality
E('Yukihiro Matsumoto')
L('Argentine', 'Bolivia', 'Chile')
Also, you could do include Reality::Methods
(instead of include Reality
)
in your code to not pollute your namespace with anything except Entity
and List
methods (E
and L
is also in this namespace after you
have required "reality/shortcuts").
- Intro
- Applications
- Links and mentions
- Tutorial:
- Tips & tricks
- Advanced topics
- Molybdenum?..