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.
3 4 5 6 |
# File 'lib/method_call_recorder/method_call.rb', line 3 def initialize(meth, *args, &blk) @method, @args = meth, args @block = blk end |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
8 9 10 |
# File 'lib/method_call_recorder/method_call.rb', line 8 def args @args end |
#block ⇒ Object (readonly)
Returns the value of attribute block.
8 9 10 |
# File 'lib/method_call_recorder/method_call.rb', line 8 def block @block end |
#method ⇒ Object
Returns the value of attribute method.
8 9 10 |
# File 'lib/method_call_recorder/method_call.rb', line 8 def method @method end |
Instance Method Details
#==(other) ⇒ Object
53 54 55 |
# File 'lib/method_call_recorder/method_call.rb', line 53 def ==(other) self.method == other.method && self.args == other.args end |
#call_on(obj) ⇒ Object
10 11 12 |
# File 'lib/method_call_recorder/method_call.rb', line 10 def call_on(obj) obj.send(method, *args) end |
#deep_dup ⇒ Object
57 58 59 |
# File 'lib/method_call_recorder/method_call.rb', line 57 def deep_dup self.class.new(method, *args, &block) end |
#getter? ⇒ Boolean
22 23 24 |
# File 'lib/method_call_recorder/method_call.rb', line 22 def getter? !setter? end |
#guess_receiver_type ⇒ Object
46 47 48 49 50 51 |
# File 'lib/method_call_recorder/method_call.rb', line 46 def guess_receiver_type case type when :array_reader, :array_writer then Array when :hash_reader, :hash_writer then Hash end end |
#setter? ⇒ Boolean
18 19 20 |
# File 'lib/method_call_recorder/method_call.rb', line 18 def setter? !!(method.to_s =~ /=$/) end |
#to_a ⇒ Object
14 15 16 |
# File 'lib/method_call_recorder/method_call.rb', line 14 def to_a [method, *args] end |
#to_s ⇒ Object
61 62 63 |
# File 'lib/method_call_recorder/method_call.rb', line 61 def to_s to_a.to_s end |
#to_setter(value) ⇒ Object
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/method_call_recorder/method_call.rb', line 26 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
37 38 39 40 41 42 43 44 |
# File 'lib/method_call_recorder/method_call.rb', line 37 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 |