Module: RubyCodeAPI::Manipulation::Update
- Included in:
- RubyCodeAPI::Manipulation
- Defined in:
- lib/manipulation/update/api.rb,
lib/manipulation/update/hash.rb,
lib/manipulation/update/token.rb,
lib/manipulation/update/value.rb,
lib/manipulation/update/position.rb
Defined Under Namespace
Modules: Hash, Position, Token, Value Classes: UpdateError
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 Value
Methods included from Hash
#hash_arg?, #matching_hash_arg?, #matching_symbol_arg?, #replace_hash_arg, #set_ldelim
Methods included from Token
#matching_string_arg?, #replace_arg_token
Methods included from Position
#position_arg?, #replace_pos_argument, #replace_position_arg
Instance Method Details
#replace(options) ⇒ Object
:arg => ‘ripper’, :replace_arg => ‘rapper’
30 31 32 33 34 35 36 37 38 |
# File 'lib/manipulation/update/api.rb', line 30 def replace() return replace_value() if [:value] if position_arg?([:arg]) puts "POSITION ARG" return replace_position_arg() end return replace_arg() if [:arg] raise UpdateError, "Invalid replace options: #{}" end |
#replace_arg(options) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/manipulation/update/api.rb', line 40 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
52 53 54 55 56 57 58 59 |
# File 'lib/manipulation/update/api.rb', line 52 def replace_argument() case self.arg when Ruby::String replace_arg_token([:with]) if matching_string_arg?([:arg]) else raise UpdateError, "Invalid replace_argument options: #{}" end end |
#update(options, &block) ⇒ Object
update :select => …, :with => … update :select => …, :with_code => ‘code’
19 20 21 22 23 24 25 26 27 |
# File 'lib/manipulation/update/api.rb', line 19 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 |