Module: RubyCodeAPI::Manipulation::Update
- Includes:
- HashReplacer, PositionReplacer, TokenReplacer, ValueReplacer
- Included in:
- RubyCodeAPI::Manipulation
- Defined in:
- lib/manipulation/update/api.rb
Instance Method Summary collapse
-
#replace(options) ⇒ Object
:arg => ‘ripper’, :replace_arg => ‘rapper’.
- #replace_arg(options) ⇒ Object
- #replace_argument(options) ⇒ Object
-
#update(options, &block) ⇒ Object
update :select => …, :with => … update :select => …, :with_code => ‘code’.
Methods included from ValueReplacer
Methods included from HashReplacer
#hash_arg?, #matching_hash_arg?, #matching_symbol_arg?, #replace_hash_arg, #set_ldelim
Methods included from TokenReplacer
#matching_string_arg?, #replace_arg_token
Methods included from PositionReplacer
#position_arg?, #replace_pos_argument, #replace_position_arg
Instance Method Details
#replace(options) ⇒ Object
:arg => ‘ripper’, :replace_arg => ‘rapper’
112 113 114 115 116 117 |
# File 'lib/manipulation/update/api.rb', line 112 def replace() return replace_value() if [:value] return replace_position_arg() if position_arg?([:arg]) return replace_arg() if [:arg] raise Error, "Invalid options: #{}" end |
#replace_arg(options) ⇒ Object
119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/manipulation/update/api.rb', line 119 def replace_arg() self.arguments.elements.each_with_index do |elem, i| case elem when Ruby::Arg if elem.hash_arg?([:arg]) return elem.replace_hash_arg() end elem.replace_argument() end end end |
#replace_argument(options) ⇒ Object
131 132 133 134 135 136 |
# File 'lib/manipulation/update/api.rb', line 131 def replace_argument() case self.arg when Ruby::String replace_arg_token([:with]) if matching_string_arg?([:arg]) end end |
#update(options, &block) ⇒ Object
update :select => …, :with => … update :select => …, :with_code => ‘code’
101 102 103 104 105 106 107 108 109 |
# File 'lib/manipulation/update/api.rb', line 101 def update(, &block) s = replace_value() if [:value] s = replace [:select].merge() if [:select] if block_given? block.arity < 1 ? s.instance_eval(&block) : block.call(s) else s end end |