Class: Moc::Protocol::Symbol
- Inherits:
-
Object
- Object
- Moc::Protocol::Symbol
- Extended by:
- Type
- Defined in:
- lib/moc/protocol/symbol.rb
Class Method Summary collapse
Instance Method Summary collapse
- #==(value) ⇒ Object
-
#initialize(value) ⇒ Symbol
constructor
A new instance of Symbol.
- #inspect ⇒ Object
- #pack ⇒ Object
- #to_i ⇒ Object
- #to_s ⇒ Object
- #to_sym ⇒ Object
Methods included from Type
Constructor Details
#initialize(value) ⇒ Symbol
Returns a new instance of Symbol.
24 25 26 27 28 29 30 |
# File 'lib/moc/protocol/symbol.rb', line 24 def initialize (value) @internal = value.respond_to?(:to_i) ? self.class.codes.key(value.to_i) : value.to_sym.upcase unless @internal && self.class.codes.member?(@internal) raise ArgumentError, "invalid symbol #{value} for #{self.class.name}" end end |
Class Method Details
.codes ⇒ Object
20 21 22 |
# File 'lib/moc/protocol/symbol.rb', line 20 def self.codes raise 'no code specification' end |
Instance Method Details
#==(value) ⇒ Object
32 33 34 35 36 37 38 39 40 |
# File 'lib/moc/protocol/symbol.rb', line 32 def == (value) return true if super return true if value.respond_to?(:to_i) && to_i == value.to_i return true if value.respond_to?(:to_sym) && to_sym == value.to_sym.upcase false end |
#inspect ⇒ Object
54 55 56 |
# File 'lib/moc/protocol/symbol.rb', line 54 def inspect "#<#{self.class.name}: #{to_s}>" end |
#pack ⇒ Object
58 59 60 |
# File 'lib/moc/protocol/symbol.rb', line 58 def pack Integer.new(to_i).pack end |
#to_i ⇒ Object
42 43 44 |
# File 'lib/moc/protocol/symbol.rb', line 42 def to_i self.class.codes[to_sym] end |
#to_s ⇒ Object
50 51 52 |
# File 'lib/moc/protocol/symbol.rb', line 50 def to_s to_sym.to_s end |
#to_sym ⇒ Object
46 47 48 |
# File 'lib/moc/protocol/symbol.rb', line 46 def to_sym @internal end |