Class: ArchSpec::MethodSignature
- Inherits:
-
Data
- Object
- Data
- ArchSpec::MethodSignature
- Defined in:
- lib/archspec/model.rb
Instance Attribute Summary collapse
-
#block ⇒ Object
readonly
Returns the value of attribute block.
-
#forward ⇒ Object
readonly
Returns the value of attribute forward.
-
#keyword_rest ⇒ Object
readonly
Returns the value of attribute keyword_rest.
-
#keywords ⇒ Object
readonly
Returns the value of attribute keywords.
-
#optional ⇒ Object
readonly
Returns the value of attribute optional.
-
#optional_keywords ⇒ Object
readonly
Returns the value of attribute optional_keywords.
-
#required ⇒ Object
readonly
Returns the value of attribute required.
-
#rest ⇒ Object
readonly
Returns the value of attribute rest.
Instance Method Summary collapse
Instance Attribute Details
#block ⇒ Object (readonly)
Returns the value of attribute block
9 10 11 |
# File 'lib/archspec/model.rb', line 9 def block @block end |
#forward ⇒ Object (readonly)
Returns the value of attribute forward
9 10 11 |
# File 'lib/archspec/model.rb', line 9 def forward @forward end |
#keyword_rest ⇒ Object (readonly)
Returns the value of attribute keyword_rest
9 10 11 |
# File 'lib/archspec/model.rb', line 9 def keyword_rest @keyword_rest end |
#keywords ⇒ Object (readonly)
Returns the value of attribute keywords
9 10 11 |
# File 'lib/archspec/model.rb', line 9 def keywords @keywords end |
#optional ⇒ Object (readonly)
Returns the value of attribute optional
9 10 11 |
# File 'lib/archspec/model.rb', line 9 def optional @optional end |
#optional_keywords ⇒ Object (readonly)
Returns the value of attribute optional_keywords
9 10 11 |
# File 'lib/archspec/model.rb', line 9 def optional_keywords @optional_keywords end |
#required ⇒ Object (readonly)
Returns the value of attribute required
9 10 11 |
# File 'lib/archspec/model.rb', line 9 def required @required end |
#rest ⇒ Object (readonly)
Returns the value of attribute rest
9 10 11 |
# File 'lib/archspec/model.rb', line 9 def rest @rest end |
Instance Method Details
#accepts_arity?(arity) ⇒ Boolean
19 20 21 22 23 24 |
# File 'lib/archspec/model.rb', line 19 def accepts_arity?(arity) return true if forward maximum = rest ? Float::INFINITY : required + optional arity >= required && arity <= maximum end |
#accepts_keywords?(names) ⇒ Boolean
26 27 28 29 30 31 32 33 34 |
# File 'lib/archspec/model.rb', line 26 def accepts_keywords?(names) return true if forward names = names.to_set return false unless keywords.all? { |name| names.include?(name) } return true if keyword_rest names.all? { |name| keywords.include?(name) || optional_keywords.include?(name) } end |
#describe ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/archspec/model.rb', line 36 def describe positional = if rest "#{required}+ positional" elsif optional.positive? "#{required}..#{required + optional} positional" else "#{required} positional" end named = (keywords.map { |name| "#{name}:" } + optional_keywords.map { |name| "#{name}:?" }).join(', ') [positional, ("keywords #{named}" unless named.empty?), ('**keywords' if keyword_rest), ('&block' if block), ('forwarding' if forward)].compact.join(', ') end |