Class: ActiveModel::Type::Binary::Data

Inherits:
Object
  • Object
show all
Defined in:
lib/active_model/type/binary.rb

Overview

:nodoc:

Instance Method Summary collapse

Constructor Details

#initialize(value) ⇒ Data

Returns a new instance of Data.



41
42
43
44
45
# File 'lib/active_model/type/binary.rb', line 41

def initialize(value)
  value = value.to_s
  value = value.b unless value.encoding == Encoding::BINARY
  @value = value
end

Instance Method Details

#==(other) ⇒ Object



56
57
58
# File 'lib/active_model/type/binary.rb', line 56

def ==(other)
  other == to_s || super
end

#hexObject



52
53
54
# File 'lib/active_model/type/binary.rb', line 52

def hex
  @value.unpack1("H*")
end

#to_sObject Also known as: to_str



47
48
49
# File 'lib/active_model/type/binary.rb', line 47

def to_s
  @value
end