Class: Uncool::Unit

Inherits:
Object
  • Object
show all
Defined in:
lib/uncool/unit.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(target, method, props = {}) ⇒ Unit

Returns a new instance of Unit.



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/uncool/unit.rb', line 9

def initialize(target, method, props={})
  @target   = target
  @method   = method.to_sym
  @function = props[:function] ? true : false
  @covered  = props[:covered]

  if @function
    @private = !@target.public_methods.find{ |m| m.to_sym == @method }
  else
    @private = !@target.public_instance_methods.find{ |m| m.to_sym == @method }
  end
end

Instance Attribute Details

#functionObject (readonly)

Returns the value of attribute function.



7
8
9
# File 'lib/uncool/unit.rb', line 7

def function
  @function
end

#methodObject (readonly)

Returns the value of attribute method.



6
7
8
# File 'lib/uncool/unit.rb', line 6

def method
  @method
end

#targetObject (readonly)

Returns the value of attribute target.



5
6
7
# File 'lib/uncool/unit.rb', line 5

def target
  @target
end

Instance Method Details

#<=>(other) ⇒ Object



64
65
66
67
68
69
70
# File 'lib/uncool/unit.rb', line 64

def <=>(other)
  c = (target.name <=> other.target.name)
  return c unless c == 0
  return -1 if function  && !other.function
  return  1 if !function && other.function
  method.to_s <=> other.method.to_s
end

#covered?Boolean

Marked as covered?

Returns:

  • (Boolean)


28
29
30
# File 'lib/uncool/unit.rb', line 28

def covered?
  @covered
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


52
53
54
55
56
57
58
# File 'lib/uncool/unit.rb', line 52

def eql?(other)
  return false unless Unit === other
  return false unless target == other.target
  return false unless method == other.method
  return false unless function == other.function
  return true
end

#function?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/uncool/unit.rb', line 33

def function?
  @function
end

#hashObject



38
39
40
# File 'lib/uncool/unit.rb', line 38

def hash
  @target.hash ^ @method.hash ^ @function.hash
end

#inspectObject



60
61
62
# File 'lib/uncool/unit.rb', line 60

def inspect
  "#{target}#{function ? '.' : '#'}#{method}"
end

#private?Boolean

Method access is private or protected?

Returns:

  • (Boolean)


23
24
25
# File 'lib/uncool/unit.rb', line 23

def private?
  @private
end

#to_sObject Also known as: to_str



43
44
45
46
47
48
49
# File 'lib/uncool/unit.rb', line 43

def to_s
  if @function
    "#{@target}.#{@method}"
  else
    "#{@target}##{@method}"
  end
end