Class: CodeWeb::MethodCall
- Inherits:
-
Object
- Object
- CodeWeb::MethodCall
- Defined in:
- lib/code_web/method_call.rb
Overview
method call reference
Instance Attribute Summary collapse
-
#args ⇒ Object
(also: #arguments)
what arguments are passed in.
-
#filename ⇒ Object
file that has this method call.
-
#is_yielding ⇒ Object
is this calling a yield block.
-
#line ⇒ Object
line number that has this method.
-
#name ⇒ Object
method name.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #arg_keys ⇒ Object
- #args? ⇒ Boolean
- #args_size ⇒ Object
- #full_method_name ⇒ Object
- #hash_arg ⇒ Object
- #hash_args? ⇒ Boolean
-
#initialize(filename, line, name = nil, args = [], is_yielding = false) ⇒ MethodCall
constructor
A new instance of MethodCall.
- #method_types ⇒ Object
- #short_filename ⇒ Object
- #short_method_name ⇒ Object
- #signature ⇒ Object
- #small_signature ⇒ Object
- #sorted_args(hash = @args) ⇒ Object
- #sorted_hash(args) ⇒ Object
-
#to_s(spaces = '') ⇒ Object
used by debugging (not sure if this should be signature).
- #yields? ⇒ Boolean
Constructor Details
#initialize(filename, line, name = nil, args = [], is_yielding = false) ⇒ MethodCall
Returns a new instance of MethodCall.
16 17 18 19 20 21 22 |
# File 'lib/code_web/method_call.rb', line 16 def initialize(filename, line, name=nil, args=[], is_yielding=false) @filename = filename @line = line @name = name @args = sorted_hash(args) @is_yielding = !! is_yielding end |
Instance Attribute Details
#args ⇒ Object Also known as: arguments
what arguments are passed in
11 12 13 |
# File 'lib/code_web/method_call.rb', line 11 def args @args end |
#filename ⇒ Object
file that has this method call
5 6 7 |
# File 'lib/code_web/method_call.rb', line 5 def filename @filename end |
#is_yielding ⇒ Object
is this calling a yield block
14 15 16 |
# File 'lib/code_web/method_call.rb', line 14 def is_yielding @is_yielding end |
#line ⇒ Object
line number that has this method
7 8 9 |
# File 'lib/code_web/method_call.rb', line 7 def line @line end |
#name ⇒ Object
method name
9 10 11 |
# File 'lib/code_web/method_call.rb', line 9 def name @name end |
Instance Method Details
#==(other) ⇒ Object
87 88 89 90 91 92 |
# File 'lib/code_web/method_call.rb', line 87 def ==(other) other && other.name == @name && other.args == @args && other.is_yielding == @is_yielding end |
#arg_keys ⇒ Object
83 84 85 |
# File 'lib/code_web/method_call.rb', line 83 def arg_keys args.first.keys end |
#args? ⇒ Boolean
24 25 26 |
# File 'lib/code_web/method_call.rb', line 24 def args? args && !args.empty? end |
#args_size ⇒ Object
75 76 77 |
# File 'lib/code_web/method_call.rb', line 75 def args_size args.size end |
#full_method_name ⇒ Object
48 49 50 |
# File 'lib/code_web/method_call.rb', line 48 def full_method_name Array(name).compact.join(".") end |
#hash_arg ⇒ Object
79 80 81 |
# File 'lib/code_web/method_call.rb', line 79 def hash_arg args.first end |
#hash_args? ⇒ Boolean
71 72 73 |
# File 'lib/code_web/method_call.rb', line 71 def hash_args? args.first.class == Hash end |
#method_types ⇒ Object
32 33 34 |
# File 'lib/code_web/method_call.rb', line 32 def method_types args.map { |arg| arg_type(arg) } end |
#short_filename ⇒ Object
52 53 54 |
# File 'lib/code_web/method_call.rb', line 52 def short_filename filename.split("/").last if filename end |
#short_method_name ⇒ Object
44 45 46 |
# File 'lib/code_web/method_call.rb', line 44 def short_method_name Array(name).last end |
#signature ⇒ Object
40 41 42 |
# File 'lib/code_web/method_call.rb', line 40 def signature "#{full_method_name}(#{sorted_args.to_s})#{" yields" if is_yielding}" end |
#small_signature ⇒ Object
36 37 38 |
# File 'lib/code_web/method_call.rb', line 36 def small_signature [arg_type(args.first), args.size] end |
#sorted_args(hash = @args) ⇒ Object
56 57 58 |
# File 'lib/code_web/method_call.rb', line 56 def sorted_args(hash=@args) hash.map {|arg| sorted_hash(arg) }.join(", ") end |
#sorted_hash(args) ⇒ Object
60 61 62 63 64 65 66 67 68 69 |
# File 'lib/code_web/method_call.rb', line 60 def sorted_hash(args) case args when Hash args.each_pair.sort_by {|n,v| n }.inject({}) {|h, (n,v)| h[n]=sorted_hash(v); h} when Array args else args end end |
#to_s(spaces = '') ⇒ Object
used by debugging (not sure if this should be signature)
95 96 97 |
# File 'lib/code_web/method_call.rb', line 95 def to_s(spaces = '') "#{spaces}#{full_method_name}(#{args.map{|arg|arg.inspect}.join(", ")})#{" do" if is_yielding}" end |
#yields? ⇒ Boolean
28 29 30 |
# File 'lib/code_web/method_call.rb', line 28 def yields? is_yielding end |