Class: String::Selection
- Inherits:
-
Object
- Object
- String::Selection
- Defined in:
- lib/core_ext/string.rb
Instance Attribute Summary collapse
-
#cursor ⇒ Object
Returns the value of attribute cursor.
-
#length ⇒ Object
Returns the value of attribute length.
-
#parent ⇒ Object
Returns the value of attribute parent.
-
#value ⇒ Object
Returns the value of attribute value.
Instance Method Summary collapse
-
#initialize(**args) ⇒ Selection
constructor
A new instance of Selection.
- #inspect ⇒ Object
- #method_missing(m, *args, &block) ⇒ Object
- #source ⇒ Object
- #source=(replacement) ⇒ Object
Constructor Details
#initialize(**args) ⇒ Selection
Returns a new instance of Selection.
9 10 11 12 13 |
# File 'lib/core_ext/string.rb', line 9 def initialize(**args) @parent = args[:parent] @cursor = args[:cursor].to_i @value = @parent[@cursor,args[:length]] end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(m, *args, &block) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/core_ext/string.rb', line 33 def method_missing(m,*args, &block) if(!args) args = [] end @value.send(m,*args,&block) # preplay action on @value to maintain length if(!!args[0] && args[0].is_a?(Integer)) args[0] = @cursor+args[0] @parent.send(m,*args,&block) else source.send(m,*args,&block) end end |
Instance Attribute Details
#cursor ⇒ Object
Returns the value of attribute cursor.
8 9 10 |
# File 'lib/core_ext/string.rb', line 8 def cursor @cursor end |
#length ⇒ Object
Returns the value of attribute length.
8 9 10 |
# File 'lib/core_ext/string.rb', line 8 def length @length end |
#parent ⇒ Object
Returns the value of attribute parent.
8 9 10 |
# File 'lib/core_ext/string.rb', line 8 def parent @parent end |
#value ⇒ Object
Returns the value of attribute value.
8 9 10 |
# File 'lib/core_ext/string.rb', line 8 def value @value end |
Instance Method Details
#inspect ⇒ Object
19 20 21 |
# File 'lib/core_ext/string.rb', line 19 def inspect return source end |
#source ⇒ Object
23 24 25 |
# File 'lib/core_ext/string.rb', line 23 def source @parent[self.cursor,self.length] end |
#source=(replacement) ⇒ Object
27 28 29 30 |
# File 'lib/core_ext/string.rb', line 27 def source=(replacement) @parent[self.cursor,self.length] = replacement @value = @parent[self.cursor,replacement.length] end |