Skip to content

Commit a371a20

Browse files
nobumatzbot
authored andcommitted
[ruby/resolv] Refine Resolv::LOC::Alt#to_s
Extract the first element instead of `join.to_i` (`String#unpack1` is available since ruby 2.4.0, but this gem still supports 2.3). ruby/resolv@f518da95ae
1 parent 380f947 commit a371a20

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

lib/resolv.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3468,8 +3468,8 @@ def initialize(altitude)
34683468
attr_reader :altitude
34693469

34703470
def to_s # :nodoc:
3471-
a = @altitude.unpack("N").join.to_i
3472-
return ((a.to_f/1e2)-1e5).to_s + "m"
3471+
a, = @altitude.unpack("N")
3472+
return "#{(a - Bias).fdiv(100)}m"
34733473
end
34743474

34753475
def inspect # :nodoc:

test/resolv/test_resource.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ def test_alt
9595
alt = Resolv::LOC::Alt.create(input)
9696

9797
assert_equal([altitude + 1e7].pack("N"), alt.altitude)
98+
assert_equal(alt, Resolv::LOC::Alt.create(alt.to_s))
9899
end
99100
end
100101

0 commit comments

Comments
 (0)