Class: AngryMob::Target::Arguments
- Defined in:
- lib/angry_mob/target/arguments.rb
Instance Attribute Summary collapse
-
#actions ⇒ Object
Returns the value of attribute actions.
-
#args ⇒ Object
readonly
Returns the value of attribute args.
Class Method Summary collapse
Instance Method Summary collapse
- #extract_actions! ⇒ Object
- #extract_args(args, &blk) ⇒ Object
-
#initialize(*args, &blk) ⇒ Arguments
constructor
A new instance of Arguments.
- #method_missing(meth, *args, &block) ⇒ Object
-
#update_preserving_actions(other_args) ⇒ Object
update args without updating actions too.
Constructor Details
#initialize(*args, &blk) ⇒ Arguments
Returns a new instance of Arguments.
6 7 8 9 |
# File 'lib/angry_mob/target/arguments.rb', line 6 def initialize(*args,&blk) @args = extract_args(args,&blk) extract_actions! end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &block) ⇒ Object
33 34 35 |
# File 'lib/angry_mob/target/arguments.rb', line 33 def method_missing(meth,*args,&block) @args.send(meth,*args,&block) end |
Instance Attribute Details
#actions ⇒ Object
Returns the value of attribute actions.
4 5 6 |
# File 'lib/angry_mob/target/arguments.rb', line 4 def actions @actions end |
#args ⇒ Object (readonly)
Returns the value of attribute args.
4 5 6 |
# File 'lib/angry_mob/target/arguments.rb', line 4 def args @args end |
Class Method Details
.parse(input, &blk) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/angry_mob/target/arguments.rb', line 11 def self.parse(input,&blk) case input when Arguments input when Array if input.size == 1 && Arguments === input.first input.first else self.new(input,&blk) end else self.new(input,&blk) end end |
Instance Method Details
#extract_actions! ⇒ Object
37 38 39 |
# File 'lib/angry_mob/target/arguments.rb', line 37 def extract_actions! @actions = [ @args.delete('actions'), @args.delete('action') ].norm.map {|s| s.to_s} end |
#extract_args(args, &blk) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/angry_mob/target/arguments.rb', line 44 def extract_args(args,&blk) args.flatten! case args.size when 0,1 if Hash === args[0] new_args = AngryHash.__convert_without_dup(args[0]) new_args.default_object = new_args else new_args = AngryHash.new new_args.default_object = args[0] end when 2 new_args = AngryHash.__convert_without_dup(args[1]) new_args.default_object = args[0] else raise ArgumentError, "usage: nickname(default_object, [ :optional_hash_of => opts ])" end new_args.__eval_as_dsl(&blk) if block_given? new_args end |
#update_preserving_actions(other_args) ⇒ Object
update args without updating actions too
27 28 29 30 31 |
# File 'lib/angry_mob/target/arguments.rb', line 27 def update_preserving_actions(other_args) other_args = self.class.parse(other_args) @args.deep_update(other_args.args) self end |