Skip to content

Commit e61a9b2

Browse files
authored
Merge pull request #380 from RickCSong/master
Fix compatibility issues for Ruby 2.4.0
2 parents 172579b + 2bc8653 commit e61a9b2

3 files changed

Lines changed: 10 additions & 3 deletions

File tree

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ rvm:
2222
- 2.2
2323
- 2.2.2
2424
- 2.3
25+
- 2.4
2526
- jruby-9.1.7.0
2627
- rbx-2
2728
env:

lib/protobuf/enum.rb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,10 +259,16 @@ def initialize(parent_class, name, tag)
259259
super(tag)
260260
end
261261

262-
# Overriding the class so ActiveRecord/Arel visitor will visit the enum as a Fixnum
262+
# Overriding the class so ActiveRecord/Arel visitor will visit the enum as an
263+
# Integer.
263264
#
264265
def class
265-
Fixnum
266+
# This is done for backward compatibility for < 2.4.0. This ensures that
267+
# if Ruby version >= 2.4.0, this will return Integer. If below, then will
268+
# return Fixnum.
269+
#
270+
# This prevents the constant deprecation warnings on Fixnum.
271+
tag.class
266272
end
267273

268274
def inspect

spec/lib/protobuf/enum_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@
214214
end
215215

216216
subject { Test::EnumTestType::ONE }
217-
specify { expect(subject.class).to eq(Fixnum) }
217+
specify { expect(subject.class).to eq(1.class) }
218218
specify { expect(subject.parent_class).to eq(Test::EnumTestType) }
219219
specify { expect(subject.name).to eq(:ONE) }
220220
specify { expect(subject.tag).to eq(1) }

0 commit comments

Comments
 (0)