Skip to content

Commit 300607c

Browse files
committed
Modernize Ruby idioms in frame.rb
1 parent e88bee6 commit 300607c

1 file changed

Lines changed: 7 additions & 7 deletions

File tree

lib/amq/protocol/frame.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ def self.encoded_payload(payload)
2323

2424
# The channel number is 0 for all frames which are global to the connection and 1-65535 for frames that refer to specific channels.
2525
def self.encode_to_array(type, payload, channel)
26-
raise RuntimeError.new("Channel has to be 0 or an integer in range 1..65535 but was #{channel.inspect}") unless CHANNEL_RANGE.include?(channel)
27-
raise RuntimeError.new("Payload can't be nil") if payload.nil?
26+
raise RuntimeError, "Channel has to be 0 or an integer in range 1..65535 but was #{channel.inspect}" unless CHANNEL_RANGE.include?(channel)
27+
raise RuntimeError, "Payload can't be nil" if payload.nil?
2828
components = []
2929
components << [find_type(type), channel, payload.bytesize].pack(PACK_CHAR_UINT16_UINT32)
3030
components << encoded_payload(payload)
@@ -47,13 +47,13 @@ def self.new(original_type, *args)
4747
end
4848

4949
def self.find_type(type)
50-
type_id = if Symbol === type then TYPES[type] else type end
51-
raise FrameTypeError.new(TYPES_OPTIONS) if type == nil || !TYPES_REVERSE.has_key?(type_id)
50+
type_id = type.is_a?(Symbol) ? TYPES[type] : type
51+
raise FrameTypeError, TYPES_OPTIONS if type.nil? || !TYPES_REVERSE.key?(type_id)
5252
type_id
5353
end
5454

5555
def self.decode(*)
56-
raise NotImplementedError.new <<-EOF
56+
raise NotImplementedError, <<-EOF
5757
You are supposed to redefine this method, because it's dependent on used IO adapter.
5858
5959
This functionality is part of the https://github.com/ruby-amqp/amq-client library.
@@ -62,12 +62,12 @@ def self.decode(*)
6262

6363
# Optimized header decode using unpack1 for single values where appropriate
6464
def self.decode_header(header)
65-
raise EmptyResponseError if header == nil || header.empty?
65+
raise EmptyResponseError if header.nil? || header.empty?
6666

6767
# Use unpack for multiple values - this is the optimal approach
6868
type_id, channel, size = header.unpack(PACK_CHAR_UINT16_UINT32)
6969
type = TYPES_REVERSE[type_id]
70-
raise FrameTypeError.new(TYPES_OPTIONS) unless type
70+
raise FrameTypeError, TYPES_OPTIONS unless type
7171
[type, channel, size]
7272
end
7373

0 commit comments

Comments
 (0)