Class: ROC::String
- Extended by:
- Types::MethodGenerators
- Includes:
- Types::ScalarType
- Defined in:
- lib/roc/objects/string.rb
Instance Attribute Summary collapse
-
#encoding ⇒ Object
readonly
Returns the value of attribute encoding.
Attributes inherited from Base
Instance Method Summary collapse
-
#append ⇒ Object
(also: #<<, #concat)
redis methods ##.
- #chr ⇒ Object
- #clear ⇒ Object
- #deserialize(val) ⇒ Object
- #empty? ⇒ Boolean
- #force_encoding(enc) ⇒ Object
-
#getbyte(ind) ⇒ Object
shortcut methods.
- #getrange(first_index, last_index) ⇒ Object (also: #substr, #substring)
-
#insert(ind, val) ⇒ Object
raise destructive methods if not implemted.
-
#replace(val) ⇒ Object
implement (if posible) destructive methods that would otherwise raise.
-
#serialize(val) ⇒ Object
implementing scalar type required methods ##.
- #setbit(index, val) ⇒ Object
- #setbyte(ind, int) ⇒ Object
- #setrange(start_index, val) ⇒ Object (also: #splice)
- #to_string ⇒ Object (also: #to_s)
Methods included from Types::MethodGenerators
deserializing_method, nonserializing_method, serializing_and_deserializing_method, serializing_method, zero_arg_method
Methods included from Types::ScalarType
Methods inherited from Base
#clobber, delegate_methods, #initialize, #method_missing, #respond_to?, #seed
Methods included from Types::AllTypes
Constructor Details
This class inherits a constructor from ROC::Base
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class ROC::Base
Instance Attribute Details
#encoding ⇒ Object (readonly)
Returns the value of attribute encoding.
11 12 13 |
# File 'lib/roc/objects/string.rb', line 11 def encoding @encoding end |
Instance Method Details
#append ⇒ Object Also known as: <<, concat
redis methods ##
20 |
# File 'lib/roc/objects/string.rb', line 20 nonserializing_method :append |
#chr ⇒ Object
64 65 66 |
# File 'lib/roc/objects/string.rb', line 64 def chr self.getrange(0, 0) end |
#clear ⇒ Object
75 76 77 |
# File 'lib/roc/objects/string.rb', line 75 def clear self.replace('') end |
#deserialize(val) ⇒ Object
107 108 109 110 111 112 113 |
# File 'lib/roc/objects/string.rb', line 107 def deserialize(val) if @encoding.nil? || !val.respond_to?(:force_encoding) val else val.force_encoding(@encoding) end end |
#empty? ⇒ Boolean
60 61 62 |
# File 'lib/roc/objects/string.rb', line 60 def empty? 0 == self.strlen end |
#force_encoding(enc) ⇒ Object
79 80 81 |
# File 'lib/roc/objects/string.rb', line 79 def force_encoding(enc) @encoding = enc end |
#getbyte(ind) ⇒ Object
shortcut methods
46 47 48 49 50 51 52 53 |
# File 'lib/roc/objects/string.rb', line 46 def getbyte(ind) val = self.getrange(ind, ind) if val.nil? || ('' == val) nil else val.bytes.to_a[0] end end |
#getrange(first_index, last_index) ⇒ Object Also known as: substr, substring
24 25 26 |
# File 'lib/roc/objects/string.rb', line 24 def getrange(first_index, last_index) self.call :getrange, first_index, last_index end |
#insert(ind, val) ⇒ Object
raise destructive methods if not implemted
85 86 87 |
# File 'lib/roc/objects/string.rb', line 85 def insert(ind, val) raise NotImplementedError end |
#replace(val) ⇒ Object
implement (if posible) destructive methods that would otherwise raise
70 71 72 73 |
# File 'lib/roc/objects/string.rb', line 70 def replace(val) self.set(val) val end |
#serialize(val) ⇒ Object
implementing scalar type required methods ##
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/roc/objects/string.rb', line 91 def serialize(val) ## use the encoding of the first val were sent unless expicitly set if @encoding.nil? @encoding = if val.respond_to?(:encoding) val.encoding else 'US-ASCII' end end if val.respond_to?(:encode) val.encode(@encoding) else val end end |
#setbit(index, val) ⇒ Object
32 33 34 |
# File 'lib/roc/objects/string.rb', line 32 def setbit(index, val) self.call :setbit, index, val end |
#setbyte(ind, int) ⇒ Object
55 56 57 58 |
# File 'lib/roc/objects/string.rb', line 55 def setbyte(ind, int) self.setrange(ind, int.chr) int end |
#setrange(start_index, val) ⇒ Object Also known as: splice
36 37 38 |
# File 'lib/roc/objects/string.rb', line 36 def setrange(start_index, val) self.call :setrange, start_index, val end |
#to_string ⇒ Object Also known as: to_s
13 14 15 |
# File 'lib/roc/objects/string.rb', line 13 def to_string self.value.to_s end |