Class: Lasp::Params
- Inherits:
-
Object
- Object
- Lasp::Params
- Defined in:
- lib/lasp/params.rb
Instance Attribute Summary collapse
-
#param_list ⇒ Object
readonly
Returns the value of attribute param_list.
Instance Method Summary collapse
- #arity ⇒ Object
-
#initialize(param_list) ⇒ Params
constructor
A new instance of Params.
- #length ⇒ Object
- #matches_arity?(num_args) ⇒ Boolean
- #ordered ⇒ Object
- #rest ⇒ Object
- #to_s ⇒ Object
- #variadic? ⇒ Boolean
Constructor Details
#initialize(param_list) ⇒ Params
Returns a new instance of Params.
7 8 9 10 11 |
# File 'lib/lasp/params.rb', line 7 def initialize(param_list) @param_list = param_list validate_params! end |
Instance Attribute Details
#param_list ⇒ Object (readonly)
Returns the value of attribute param_list.
5 6 7 |
# File 'lib/lasp/params.rb', line 5 def param_list @param_list end |
Instance Method Details
#arity ⇒ Object
28 29 30 |
# File 'lib/lasp/params.rb', line 28 def arity ordered.length.to_s + (variadic? ? "+" : "") end |
#length ⇒ Object
40 41 42 |
# File 'lib/lasp/params.rb', line 40 def length ordered.length end |
#matches_arity?(num_args) ⇒ Boolean
32 33 34 35 36 37 38 |
# File 'lib/lasp/params.rb', line 32 def matches_arity?(num_args) if variadic? num_args >= length else num_args == length end end |
#ordered ⇒ Object
13 14 15 |
# File 'lib/lasp/params.rb', line 13 def ordered param_list.take_while { |p| p != :& } end |
#rest ⇒ Object
17 18 19 20 21 22 |
# File 'lib/lasp/params.rb', line 17 def rest unless variadic? fail LaspError, "a non-variadic function does not have rest-arguments" end param_list.last end |
#to_s ⇒ Object
44 45 46 |
# File 'lib/lasp/params.rb', line 44 def to_s "(" + param_list.join(" ") + ")" end |
#variadic? ⇒ Boolean
24 25 26 |
# File 'lib/lasp/params.rb', line 24 def variadic? param_list.include?(:&) end |