Class: MethodCall
- Inherits:
-
Object
- Object
- MethodCall
- Defined in:
- lib/method_call_recorder/method_call.rb
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
-
#block ⇒ Object
readonly
Returns the value of attribute block.
-
#method ⇒ Object
readonly
Returns the value of attribute method.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #call_on(obj) ⇒ Object
- #deep_dup ⇒ Object
- #getter? ⇒ Boolean
- #guess_receiver_type ⇒ Object
-
#initialize(meth, *args, &blk) ⇒ MethodCall
constructor
A new instance of MethodCall.
- #setter? ⇒ Boolean
- #to_a ⇒ Object
- #to_s ⇒ Object
- #to_setter(value) ⇒ Object
- #type ⇒ Object
Constructor Details
#initialize(meth, *args, &blk) ⇒ MethodCall
Returns a new instance of MethodCall.
4 5 6 7 |
# File 'lib/method_call_recorder/method_call.rb', line 4 def initialize(meth, *args, &blk) @method, @args = meth, args @block = blk end |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
9 10 11 |
# File 'lib/method_call_recorder/method_call.rb', line 9 def args @args end |
#block ⇒ Object (readonly)
Returns the value of attribute block.
9 10 11 |
# File 'lib/method_call_recorder/method_call.rb', line 9 def block @block end |
#method ⇒ Object
Returns the value of attribute method.
9 10 11 |
# File 'lib/method_call_recorder/method_call.rb', line 9 def method @method end |
Instance Method Details
#==(other) ⇒ Object
54 55 56 |
# File 'lib/method_call_recorder/method_call.rb', line 54 def ==(other) self.method == other.method && self.args == other.args end |
#call_on(obj) ⇒ Object
11 12 13 |
# File 'lib/method_call_recorder/method_call.rb', line 11 def call_on(obj) obj.send(method, *args) end |
#deep_dup ⇒ Object
58 59 60 |
# File 'lib/method_call_recorder/method_call.rb', line 58 def deep_dup self.class.new(method, *args, &block) end |
#getter? ⇒ Boolean
23 24 25 |
# File 'lib/method_call_recorder/method_call.rb', line 23 def getter? !setter? end |
#guess_receiver_type ⇒ Object
47 48 49 50 51 52 |
# File 'lib/method_call_recorder/method_call.rb', line 47 def guess_receiver_type case type when :array_reader, :array_writer then Array when :hash_reader, :hash_writer then Hash end end |
#setter? ⇒ Boolean
19 20 21 |
# File 'lib/method_call_recorder/method_call.rb', line 19 def setter? !!(method.to_s =~ /=$/) end |
#to_a ⇒ Object
15 16 17 |
# File 'lib/method_call_recorder/method_call.rb', line 15 def to_a [method, *args] end |
#to_s ⇒ Object
62 63 64 |
# File 'lib/method_call_recorder/method_call.rb', line 62 def to_s to_a.to_s end |
#to_setter(value) ⇒ Object
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/method_call_recorder/method_call.rb', line 27 def to_setter(value) new_method_call = self.deep_dup if setter? new_method_call.args[-1] = value else new_method_call.args << value new_method_call.method = "#{new_method_call.method}=".to_sym end new_method_call end |
#type ⇒ Object
38 39 40 41 42 43 44 45 |
# File 'lib/method_call_recorder/method_call.rb', line 38 def type case method.to_s when '[]' then (args.first.is_a?(Fixnum) ? :array_reader : :hash_reader) when '[]=' then (args.first.is_a?(Fixnum) ? :array_writer : :hash_writer) when /\=$/ then :attr_writer else :attr_reader end end |