forked from msgpack/msgpack-ruby
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcore_ext.rb
More file actions
139 lines (116 loc) · 2.1 KB
/
core_ext.rb
File metadata and controls
139 lines (116 loc) · 2.1 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
module MessagePack
module CoreExt
def to_msgpack(packer_or_io = nil)
if packer_or_io
if packer_or_io.is_a?(MessagePack::Packer)
to_msgpack_with_packer packer_or_io
else
MessagePack.pack(self, packer_or_io)
end
else
MessagePack.pack(self)
end
end
end
end
class NilClass
include MessagePack::CoreExt
private
def to_msgpack_with_packer(packer)
packer.write_nil
packer
end
end
class TrueClass
include MessagePack::CoreExt
private
def to_msgpack_with_packer(packer)
packer.write_true
packer
end
end
class FalseClass
include MessagePack::CoreExt
private
def to_msgpack_with_packer(packer)
packer.write_false
packer
end
end
class Float
include MessagePack::CoreExt
private
def to_msgpack_with_packer(packer)
packer.write_float self
packer
end
end
class String
include MessagePack::CoreExt
private
def to_msgpack_with_packer(packer)
packer.write_string self
packer
end
end
class Array
include MessagePack::CoreExt
private
def to_msgpack_with_packer(packer)
packer.write_array self
packer
end
end
class Hash
include MessagePack::CoreExt
private
def to_msgpack_with_packer(packer)
packer.write_hash self
packer
end
end
class Symbol
include MessagePack::CoreExt
private
def to_msgpack_with_packer(packer)
packer.write_symbol self
packer
end
end
if 1.class.name == "Integer"
class Integer
include MessagePack::CoreExt
private
def to_msgpack_with_packer(packer)
packer.write_int self
packer
end
end
else
class Fixnum
include MessagePack::CoreExt
private
def to_msgpack_with_packer(packer)
packer.write_int self
packer
end
end
class Bignum
include MessagePack::CoreExt
private
def to_msgpack_with_packer(packer)
packer.write_int self
packer
end
end
end
module MessagePack
class ExtensionValue
include CoreExt
private
def to_msgpack_with_packer(packer)
packer.write_extension self
packer
end
end
end