mirror of
https://github.com/meineerde/rackstash.git
synced 2026-01-31 17:27:13 +00:00
Add Fields::Hash#length to emulate Hash#length
This commit is contained in:
parent
d382a245f3
commit
e472b7fbce
@ -290,6 +290,12 @@ module Rackstash
|
||||
@raw.keys
|
||||
end
|
||||
|
||||
# @return [Integer] the number of key-value pairs in the hash
|
||||
def length
|
||||
@raw.length
|
||||
end
|
||||
alias size length
|
||||
|
||||
# Returns a new {Hash} containing the contents of `hash` and of
|
||||
# `self`. If no block is specified, the value for entries with duplicate
|
||||
# keys will be that of `hash`. Otherwise the value for each duplicate key
|
||||
|
||||
@ -495,6 +495,24 @@ describe Rackstash::Fields::Hash do
|
||||
end
|
||||
end
|
||||
|
||||
describe '#length' do
|
||||
it 'returns the length of the hash' do
|
||||
expect(hash.length).to eql 0
|
||||
|
||||
hash['foo'] = 'bar'
|
||||
expect(hash.length).to eql 1
|
||||
|
||||
hash.clear
|
||||
expect(hash.length).to eql 0
|
||||
end
|
||||
|
||||
it 'can use size as an alias' do
|
||||
expect(hash.size).to eql 0
|
||||
hash['foo'] = 'bar'
|
||||
expect(hash.size).to eql 1
|
||||
end
|
||||
end
|
||||
|
||||
describe '#merge!' do
|
||||
it 'rejects not hash-convertible arguments' do
|
||||
expect { hash.merge!(nil) }.to raise_error TypeError
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user