Add more methods to Micro::Case::Result quack like a Hash
serradura opened this issue · 1 comments
serradura commented
Definition of Done:
Add these new methods into Micro::Case::Result
:
-
#key?
- https://apidock.com/ruby/v2_2_9/Hash/key%3F -
#value?
- https://apidock.com/ruby/v2_2_9/Hash/value%3F -
#slice()
- https://apidock.com/ruby/v2_5_5/Hash/slice
Documentation
- Update README.md - https://github.com/serradura/u-case/blob/769b9bfbc8440c81a1e8a6811369f2819a21a07a/README.md#microcaseresult---what-is-a-use-case-result
Look here to see the implementation of the methods #[]
and #values_at()
.
Below are the places to put the tests to assert these new methods:
- https://github.com/serradura/u-case/blob/main/test/micro/case/result_test.rb#L59-L62
- https://github.com/serradura/u-case/blob/main/test/micro/case/result_test.rb#L105-L108
Because of the Hash#slice
method does not exists in older Ruby versions, we will need to create an util to do this inside of Micro::Case::Result#slice
. e.g:
module Micro
class Case
module Utils
def self.slice_hash(hash, keys)
if Kind::Of::Hash(hash).respond_to?(:slice)
hash.slice(*keys)
else
hash.select { |key, _value| keys.include?(key) }
end
end
end
end
end