Class: CodeWeb::MethodCall

Inherits:
Object
  • Object
show all
Defined in:
lib/code_web/method_call.rb

Overview

method call reference

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#argsObject 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

#filenameObject

file that has this method call



5
6
7
# File 'lib/code_web/method_call.rb', line 5

def filename
  @filename
end

#is_yieldingObject

is this calling a yield block



14
15
16
# File 'lib/code_web/method_call.rb', line 14

def is_yielding
  @is_yielding
end

#lineObject

line number that has this method



7
8
9
# File 'lib/code_web/method_call.rb', line 7

def line
  @line
end

#nameObject

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_keysObject



83
84
85
# File 'lib/code_web/method_call.rb', line 83

def arg_keys
  args.first.keys
end

#args?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/code_web/method_call.rb', line 24

def args?
  args && !args.empty?
end

#args_sizeObject



75
76
77
# File 'lib/code_web/method_call.rb', line 75

def args_size
  args.size
end

#full_method_nameObject



48
49
50
# File 'lib/code_web/method_call.rb', line 48

def full_method_name
  Array(name).compact.join(".")
end

#hash_argObject



79
80
81
# File 'lib/code_web/method_call.rb', line 79

def hash_arg
  args.first
end

#hash_args?Boolean

Returns:

  • (Boolean)


71
72
73
# File 'lib/code_web/method_call.rb', line 71

def hash_args?
  args.first.class == Hash
end

#method_typesObject



32
33
34
# File 'lib/code_web/method_call.rb', line 32

def method_types
  args.map { |arg| arg_type(arg) }
end

#short_filenameObject



52
53
54
# File 'lib/code_web/method_call.rb', line 52

def short_filename
  filename.split("/").last if filename
end

#short_method_nameObject



44
45
46
# File 'lib/code_web/method_call.rb', line 44

def short_method_name
  Array(name).last
end

#signatureObject



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_signatureObject



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

Returns:

  • (Boolean)


28
29
30
# File 'lib/code_web/method_call.rb', line 28

def yields?
  is_yielding
end