tobie (owner)

Revisions

gist: 78355 Download_button fork
public
Description:
Ruby p() of common types
Public Clone URL: git://gist.github.com/78355.git
Embed All Files: show embed
Ruby #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
p(nil)
#-> nil
 
p(false)
#-> false
 
p(true)
#-> true
 
p('foo')
#-> "foo"
 
p(123)
#-> 123
 
p(123.4)
#-> 123.4
 
p(/foo/)
#-> /foo/
 
p(Time.now)
#-> Fri Mar 13 00:21:41 +0100 2009
 
p([0, 1, [2, 3]])
#-> [0, 1, [2, 3]]
 
{:foo => 123}
#-> {:foo=>123}
 
# self-containing arrays
a = [1, 2, 3]
a << a
p(a)
#-> [1, 2, 3, [...]]
 
# self-containing hashes
h = {:foo => 123}
h[:bar] = h
#-> {:foo=>123, :bar=>{...}}
 
# custom class
class Foo
  def initialize
    @bar = 123
    @foo = 456
  end
end
 
p(Foo)
#-> Foo
 
p(Foo.new)
#-> #<Foo:0x8e7d8 @foo=456, @bar=123>
 
p([].method('reverse'))
#-> #<Method: Array#reverse>