beefcake 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/lib/beefcake.rb +9 -0
  2. data/test/message_test.rb +6 -0
  3. metadata +3 -3
data/lib/beefcake.rb CHANGED
@@ -229,6 +229,15 @@ module Beefcake
229
229
  "<#{self.class.name} #{flds.join(", ")}>"
230
230
  end
231
231
 
232
+ def to_hash
233
+ fields.values.inject({}) do |h, fld|
234
+ if v = self[fld.name]
235
+ h[fld.name] = v
236
+ end
237
+ h
238
+ end
239
+ end
240
+
232
241
  end
233
242
 
234
243
  end
data/test/message_test.rb CHANGED
@@ -325,4 +325,10 @@ class MessageTest < Test::Unit::TestCase
325
325
  assert_equal "<EnumsMessage a: -NA-(2)>", msg.inspect
326
326
  end
327
327
 
328
+ def test_to_hash
329
+ msg = SimpleMessage.new :a => 1
330
+ exp = { :a => 1 }
331
+ assert_equal(exp, msg.to_hash)
332
+ end
333
+
328
334
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: beefcake
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 21
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 0
10
- version: 0.2.0
9
+ - 1
10
+ version: 0.2.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Blake Mizerany