Class: RSpec::SleepingKingStudios::Support::MethodSignature Private

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec/sleeping_king_studios/support/method_signature.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(method) ⇒ MethodSignature

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of MethodSignature.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/rspec/sleeping_king_studios/support/method_signature.rb', line 8

def initialize method
  parameters = method.parameters

  required = parameters.count { |type, _| :req  == type }
  optional = parameters.count { |type, _| :opt  == type }
  variadic = parameters.count { |type, _| :rest == type }

  @min_arguments       = required
  @max_arguments       = required + optional
  @unlimited_arguments = variadic > 0

  required = parameters.select { |type, _| :keyreq  == type }.map { |_, keyword| keyword }
  optional = parameters.select { |type, _| :key     == type }.map { |_, keyword| keyword }
  variadic = parameters.count  { |type, _| :keyrest == type }

  @required_keywords = required
  @optional_keywords = optional
  @any_keywords      = variadic > 0

  @block_argument = parameters.count { |type, _| :block == type } > 0
end

Instance Attribute Details

#max_argumentsObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

method initialize



30
31
32
# File 'lib/rspec/sleeping_king_studios/support/method_signature.rb', line 30

def max_arguments
  @max_arguments
end

#min_argumentsObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

method initialize



30
31
32
# File 'lib/rspec/sleeping_king_studios/support/method_signature.rb', line 30

def min_arguments
  @min_arguments
end

#optional_keywordsObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

method initialize



30
31
32
# File 'lib/rspec/sleeping_king_studios/support/method_signature.rb', line 30

def optional_keywords
  @optional_keywords
end

#required_keywordsObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

method initialize



30
31
32
# File 'lib/rspec/sleeping_king_studios/support/method_signature.rb', line 30

def required_keywords
  @required_keywords
end

Instance Method Details

#any_keywords?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


35
36
37
# File 'lib/rspec/sleeping_king_studios/support/method_signature.rb', line 35

def any_keywords?
  !!@any_keywords
end

#block_argument?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

method any_keywords?

Returns:

  • (Boolean)


39
40
41
# File 'lib/rspec/sleeping_king_studios/support/method_signature.rb', line 39

def block_argument?
  !!@block_argument
end

#keywordsObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

method block_argument?



43
44
45
# File 'lib/rspec/sleeping_king_studios/support/method_signature.rb', line 43

def keywords
  @optional_keywords + @required_keywords
end

#unlimited_arguments?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

method keywords

Returns:

  • (Boolean)


47
48
49
# File 'lib/rspec/sleeping_king_studios/support/method_signature.rb', line 47

def unlimited_arguments?
  !!@unlimited_arguments
end