Class: Uncool::Unit
- Inherits:
-
Object
- Object
- Uncool::Unit
- Defined in:
- lib/uncool/unit.rb
Instance Attribute Summary collapse
-
#function ⇒ Object
readonly
Returns the value of attribute function.
-
#method ⇒ Object
readonly
Returns the value of attribute method.
-
#target ⇒ Object
readonly
Returns the value of attribute target.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#covered? ⇒ Boolean
Marked as covered?.
- #eql?(other) ⇒ Boolean
- #function? ⇒ Boolean
- #hash ⇒ Object
-
#initialize(target, method, props = {}) ⇒ Unit
constructor
A new instance of Unit.
- #inspect ⇒ Object
-
#private? ⇒ Boolean
Method access is private or protected?.
- #to_s ⇒ Object (also: #to_str)
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
#function ⇒ Object (readonly)
Returns the value of attribute function.
7 8 9 |
# File 'lib/uncool/unit.rb', line 7 def function @function end |
#method ⇒ Object (readonly)
Returns the value of attribute method.
6 7 8 |
# File 'lib/uncool/unit.rb', line 6 def method @method end |
#target ⇒ Object (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?
28 29 30 |
# File 'lib/uncool/unit.rb', line 28 def covered? @covered end |
#eql?(other) ⇒ 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
33 34 35 |
# File 'lib/uncool/unit.rb', line 33 def function? @function end |
#hash ⇒ Object
38 39 40 |
# File 'lib/uncool/unit.rb', line 38 def hash @target.hash ^ @method.hash ^ @function.hash end |
#inspect ⇒ Object
60 61 62 |
# File 'lib/uncool/unit.rb', line 60 def inspect "#{target}#{function ? '.' : '#'}#{method}" end |
#private? ⇒ Boolean
Method access is private or protected?
23 24 25 |
# File 'lib/uncool/unit.rb', line 23 def private? @private end |
#to_s ⇒ Object 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 |