class CodeWeb::MethodCall

method call reference

Attributes

args[RW]

what arguments are passed in

arguments[RW]

what arguments are passed in

filename[RW]

file that has this method call

is_yielding[RW]

is this calling a yield block

line[RW]

line number that has this method

name[RW]

method name

Public Class Methods

new(filename, line, name=nil, args=[], is_yielding=false) click to toggle source
# 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

Public Instance Methods

==(other) click to toggle source
# 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() click to toggle source
# File lib/code_web/method_call.rb, line 83
def arg_keys
  args.first.keys
end
args?() click to toggle source
# File lib/code_web/method_call.rb, line 24
def args?
  args && !args.empty?
end
args_size() click to toggle source
# File lib/code_web/method_call.rb, line 75
def args_size
  args.size
end
full_method_name() click to toggle source
# File lib/code_web/method_call.rb, line 48
def full_method_name
  Array(name).compact.join(".")
end
hash_arg() click to toggle source
# File lib/code_web/method_call.rb, line 79
def hash_arg
  args.first
end
hash_args?() click to toggle source
# File lib/code_web/method_call.rb, line 71
def hash_args?
  args.first.class == Hash
end
method_types() click to toggle source
# File lib/code_web/method_call.rb, line 32
def method_types
  args.map { |arg| arg_type(arg) }
end
short_filename() click to toggle source
# File lib/code_web/method_call.rb, line 52
def short_filename
  filename.split("/").last if filename
end
short_method_name() click to toggle source
# File lib/code_web/method_call.rb, line 44
def short_method_name
  Array(name).last
end
signature() click to toggle source
# 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() click to toggle source
# File lib/code_web/method_call.rb, line 36
def small_signature
  [arg_type(args.first), args.size]
end
sorted_args(hash=@args) click to toggle source
# 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) click to toggle source
# 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 = '') click to toggle source

used by debugging (not sure if this should be signature)

# 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?() click to toggle source
# File lib/code_web/method_call.rb, line 28
def yields?
  is_yielding
end

Private Instance Methods

arg_type(arg) click to toggle source
# File lib/code_web/method_call.rb, line 101
def arg_type(arg)
  case arg
  when Array
    '[]'
  when Hash
    '{}'
  when nil
    "nil"
  when Symbol
    ':'
  else
    'str'
  end
end