Class: Dentaku::AST::StringFunctions::Substitute
- Defined in:
- lib/dentaku/ast/functions/string_functions.rb
Constant Summary
Constants inherited from Function
Instance Attribute Summary
Attributes inherited from Function
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(*args) ⇒ Substitute
constructor
A new instance of Substitute.
- #value(context = {}) ⇒ Object
Methods inherited from Base
#negative_argument_failure, #type
Methods inherited from Function
#accept, #dependencies, get, numeric, register, register_class, registry
Methods inherited from Node
arity, #dependencies, #name, precedence, resolve_class, #type
Constructor Details
#initialize(*args) ⇒ Substitute
Returns a new instance of Substitute.
147 148 149 150 |
# File 'lib/dentaku/ast/functions/string_functions.rb', line 147 def initialize(*args) super @original, @search, @replacement = *@args end |
Class Method Details
.max_param_count ⇒ Object
143 144 145 |
# File 'lib/dentaku/ast/functions/string_functions.rb', line 143 def self.max_param_count 3 end |
.min_param_count ⇒ Object
139 140 141 |
# File 'lib/dentaku/ast/functions/string_functions.rb', line 139 def self.min_param_count 3 end |
Instance Method Details
#value(context = {}) ⇒ Object
152 153 154 155 156 157 158 |
# File 'lib/dentaku/ast/functions/string_functions.rb', line 152 def value(context = {}) original = @original.value(context).to_s search = @search.value(context) search = search.to_s unless search.is_a?(Regexp) replacement = @replacement.value(context).to_s original.sub(search, replacement) end |