Module: Calldata
- Defined in:
- lib/calldata.rb
Class Method Summary collapse
- .decode(hex) ⇒ Object (also: decode_hex)
- .encode(utf8) ⇒ Object (also: encode_utf8)
- .valid?(hex) ⇒ Boolean (also: is_valid?)
Class Method Details
.decode(hex) ⇒ Object Also known as: decode_hex
63 64 65 66 67 68 69 |
# File 'lib/calldata.rb', line 63 def self.decode( hex ) raise TypeError, "Calldata.decode - String expected; got #{hex.inspect} : #{hex.class.name}" unless hex.is_a?( String ) raise ArgumentError, "Calldata.decode - hexstring expected; got #{hex}" unless valid?( hex ) ## todo/check - add a regex/format check here - why? why not? ## must be string and hexchars only (0x/0X) hex_to_utf8( hex ) end |
.encode(utf8) ⇒ Object Also known as: encode_utf8
57 58 59 60 61 |
# File 'lib/calldata.rb', line 57 def self.encode( utf8 ) raise TypeError, "Calldata.encode - String expected; got #{utf8.inspect} : #{utf8.class.name}" unless utf8.is_a?( String ) ## note: no 0x upfront for now - why? why not? utf8_to_hex( utf8 ) end |
.valid?(hex) ⇒ Boolean Also known as: is_valid?
71 72 73 |
# File 'lib/calldata.rb', line 71 def self.valid?( hex ) is_hex?( hex ) end |