Class: ApiDiff::Function

Inherits:
Object
  • Object
show all
Defined in:
lib/api_diff/function.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, signature:, return_type:, static:, constructor:) ⇒ Function

Returns a new instance of Function.



5
6
7
8
9
10
11
# File 'lib/api_diff/function.rb', line 5

def initialize(name:, signature:, return_type:, static:, constructor:)
  @name = name
  @signature = signature
  @return_type = return_type
  @static = static
  @constructor = constructor
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/api_diff/function.rb', line 3

def name
  @name
end

#return_typeObject (readonly)

Returns the value of attribute return_type.



3
4
5
# File 'lib/api_diff/function.rb', line 3

def return_type
  @return_type
end

#signatureObject (readonly)

Returns the value of attribute signature.



3
4
5
# File 'lib/api_diff/function.rb', line 3

def signature
  @signature
end

Instance Method Details

#<=>(other) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/api_diff/function.rb', line 41

def <=>(other)
  # static at the bottom
  return 1 if is_static? and not other.is_static?
  return -1 if not is_static? and other.is_static?

  # constructors first
  return -1 if is_constructor? and not other.is_constructor?
  return 1 if not is_constructor? and other.is_constructor?

  if is_constructor?
    # sort constructors by length
    [full_signature.size, full_signature] <=> [other.full_signature.size, other.full_signature]
  else
    [name, full_signature] <=> [other.name, other.full_signature]
  end
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/api_diff/function.rb', line 37

def eql?(other)
  full_signature == other.full_signature
end

#full_signatureObject



25
26
27
28
29
30
31
# File 'lib/api_diff/function.rb', line 25

def full_signature
  if return_type.nil?
    signature
  else
    "#{signature} -> #{return_type}"
  end
end

#hashObject



33
34
35
# File 'lib/api_diff/function.rb', line 33

def hash
  full_signature.hash
end

#is_constructor?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/api_diff/function.rb', line 13

def is_constructor?
  @constructor
end

#is_static?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/api_diff/function.rb', line 17

def is_static?
  @static
end

#to_sObject



21
22
23
# File 'lib/api_diff/function.rb', line 21

def to_s
  full_signature
end