Method: Klay::Rlp::Sedes.infer
- Defined in:
- lib/klay/rlp/sedes.rb
.infer(obj) ⇒ Object
Tries to find a sedes objects suitable for a given Ruby object.
The sedes objects considered are obj
's class, big_endian_int and
binary. If obj
is a list, an List will be
constructed recursively.
41 42 43 44 45 46 47 |
# File 'lib/klay/rlp/sedes.rb', line 41 def infer(obj) return obj.class if is_sedes? obj.class return big_endian_int if obj.is_a?(Integer) && obj >= 0 return binary if Binary.valid_type? obj return List.new(elements: obj.map { |item| infer item }) if Util.is_list? obj raise TypeError, "Did not find sedes handling type #{obj.class.name}" end |