Class: Code::Object::Parameter
Constant Summary
collapse
- CLASS_DOCUMENTATION =
{
name: "Parameter",
description:
"describes one function parameter with its name, kind flags, and default value.",
examples: [
"((name) => { name }).parameters.first",
"((name:) => { name }).parameters.first.keyword?",
"((name = :a) => { name }).parameters.first.default"
]
}.freeze
- INSTANCE_FUNCTIONS =
{
"name" => {
name: "name",
description: "returns the parameter identifier name.",
examples: [
"((name) => { name }).parameters.first.name",
"((name = :a) => { name }).parameters.first.name",
"((...values) => { values }).parameters.first.name"
]
},
"regular?" => {
name: "regular?",
description:
"returns whether the parameter is not a keyword parameter.",
examples: [
"((name) => { name }).parameters.first.regular?",
"((name:) => { name }).parameters.first.regular?",
"((...values) => { values }).parameters.first.regular?"
]
},
"keyword?" => {
name: "keyword?",
description:
"returns whether the parameter is a named keyword parameter.",
examples: [
"((name:) => { name }).parameters.first.keyword?",
"((name) => { name }).parameters.first.keyword?",
"((**options) => { options }).parameters.first.keyword?"
]
},
"regular_splat?" => {
name: "regular_splat?",
description:
"returns whether the parameter captures positional arguments with *.",
examples: [
"((...values) => { values }).parameters.first.regular_splat?",
"((*values) => { values }).parameters.first.regular_splat?",
"((name) => { name }).parameters.first.regular_splat?"
]
},
"keyword_splat?" => {
name: "keyword_splat?",
description:
"returns whether the parameter captures keyword arguments with **.",
examples: [
"((**options) => { options }).parameters.first.keyword_splat?",
"((name:) => { name }).parameters.first.keyword_splat?",
"((name) => { name }).parameters.first.keyword_splat?"
]
},
"block?" => {
name: "block?",
description:
"returns whether the parameter captures one function argument with &.",
examples: [
"((&block) => { block }).parameters.first.block?",
"((name) => { name }).parameters.first.block?",
"((&&blocks) => { blocks }).parameters.first.block?"
]
},
"blocks?" => {
name: "blocks?",
description:
"returns whether the parameter captures remaining function arguments with &&.",
examples: [
"((&&blocks) => { blocks }).parameters.first.blocks?",
"((&block) => { block }).parameters.first.blocks?",
"((name) => { name }).parameters.first.blocks?"
]
},
"spread?" => {
name: "spread?",
description:
"returns whether the parameter captures every provided argument with spread syntax.",
examples: [
"((...values) => { values }).parameters.first.spread?",
"((name) => { name }).parameters.first.spread?",
"((name:) => { name }).parameters.first.spread?"
]
},
"required?" => {
name: "required?",
description: "returns whether the parameter has no default value.",
examples: [
"((name) => { name }).parameters.first.required?",
"((name = :a) => { name }).parameters.first.required?",
"((name:) => { name }).parameters.first.required?"
]
},
"optional?" => {
name: "optional?",
description: "returns whether the parameter has a default value.",
examples: [
"((name = :a) => { name }).parameters.first.optional?",
"((name) => { name }).parameters.first.optional?",
"((name: :a) => { name }).parameters.first.optional?"
]
},
"default" => {
name: "default",
description:
"returns the default value for the parameter, or nothing when none is set.",
examples: [
"((name = :a) => { name }).parameters.first.default",
"((name) => { name }).parameters.first.default",
"((name: :a) => { name }).parameters.first.default"
]
}
}.freeze
Constants inherited
from Dictionary
Dictionary::CLASS_FUNCTIONS
Constants inherited
from Code::Object
CLASS_FUNCTIONS, NUMBER_CLASSES
Concerns::Shared::COMPOUND_ASSIGNMENT_OPERATORS, Concerns::Shared::OPERATOR_METHOD_ALIASES, Concerns::Shared::SHARED_OPERATORS
Instance Attribute Summary
#functions, #raw
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Dictionary
#<=>, call, #code_any?, code_assign, #code_associate, #code_clear, #code_compact, #code_compact!, #code_deep_duplicate, #code_delete, #code_delete_if, #code_delete_unless, #code_dig, #code_each, #code_each_key, #code_each_pair, #code_each_value, #code_empty?, code_entries, #code_except, #code_fetch, #code_fetch_values, #code_flatten, code_from_entries, #code_get, #code_has_key?, code_has_own?, #code_has_own?, #code_has_value?, #code_invert, #code_keep_if, #code_keep_unless, #code_key, #code_keys, #code_map, #code_merge, #code_merge!, #code_reject, #code_reject!, #code_replace, #code_right_associate, #code_select, #code_select!, #code_set, #code_shift, #code_size, #code_slice, #code_store, #code_to_context, #code_to_dictionary, #code_to_list, #code_to_query, #code_transform_keys, #code_transform_keys!, #code_transform_values, #code_transform_values!, #code_update, #code_values, #code_values_at, #initialize, #present?
class_documentation, class_functions, code_new, #code_new, documentation, documentation_for, documented_functions_for, function_documentation_for, function_documentation_registry_for, functions, inherited_function_documentation_for, #initialize, instance_functions, maybe, #name, repeat, sorted_dictionary, |
#<=>, #==, #as_json, #blank?, #code_and, #code_as_json, #code_blank?, #code_class_functions, #code_compare, #code_deep_duplicate, #code_different, #code_documentable_functions, #code_documentation, #code_duplicate, #code_dynamic_call, #code_equal, #code_exclamation_mark, #code_exclusive_range, #code_false?, #code_falsy?, code_fetch, #code_fetch, #code_functions, code_get, #code_get, #code_greater, #code_greater_or_equal, #code_has_key?, #code_inclusive_range, #code_inspect, #code_instance_functions, #code_instance_of?, #code_is_a?, #code_itself, #code_less, #code_less_or_equal, #code_nothing?, #code_or, #code_presence, #code_presence_in, #code_present?, #code_respond_to?, #code_same_object?, #code_self, #code_send, code_set, #code_set, #code_something?, #code_strict_different, #code_strict_equal, #code_tap, #code_then, #code_to_boolean, #code_to_class, #code_to_date, #code_to_decimal, #code_to_dictionary, #code_to_duration, #code_to_integer, #code_to_json, #code_to_list, #code_to_nothing, #code_to_parameter, #code_to_range, #code_to_string, #code_to_time, #code_true?, #code_truthy?, #eql?, #falsy?, #hash, #inspect, #multi_fetch, #nothing?, #present?, #sig, #something?, #succ, #to_code, #to_i, #to_json, #to_s, #truthy?
Class Method Details
.function_documentation(scope) ⇒ Object
126
127
128
129
130
|
# File 'lib/code/object/parameter.rb', line 126
def self.function_documentation(scope)
return INSTANCE_FUNCTIONS if scope == :instance
{}
end
|
Instance Method Details
219
220
221
|
# File 'lib/code/object/parameter.rb', line 219
def block?
code_block?.truthy?
end
|
223
224
225
|
# File 'lib/code/object/parameter.rb', line 223
def blocks?
code_blocks?.truthy?
end
|
#call(**args) ⇒ Object
132
133
134
135
136
137
138
139
140
141
142
143
144
145
|
# File 'lib/code/object/parameter.rb', line 132
def call(**args)
code_operator = args.fetch(:operator, nil).to_code
case code_operator.to_s
when "required?"
sig(args)
code_required?
when "optional?"
sig(args)
code_optional?
else
super
end
end
|
#code_block? ⇒ Boolean
167
168
169
|
# File 'lib/code/object/parameter.rb', line 167
def code_block?
Boolean.new(code_get(:block?))
end
|
#code_blocks? ⇒ Boolean
171
172
173
|
# File 'lib/code/object/parameter.rb', line 171
def code_blocks?
Boolean.new(code_get(:blocks?))
end
|
#code_default ⇒ Object
187
188
189
|
# File 'lib/code/object/parameter.rb', line 187
def code_default
code_get(:default).to_code
end
|
#code_keyword? ⇒ Boolean
155
156
157
|
# File 'lib/code/object/parameter.rb', line 155
def code_keyword?
Boolean.new(code_get(:keyword?))
end
|
#code_keyword_splat? ⇒ Boolean
163
164
165
|
# File 'lib/code/object/parameter.rb', line 163
def code_keyword_splat?
Boolean.new(code_get(:keyword_splat?))
end
|
#code_name ⇒ Object
147
148
149
|
# File 'lib/code/object/parameter.rb', line 147
def code_name
String.new(code_get(:name))
end
|
#code_optional? ⇒ Boolean
183
184
185
|
# File 'lib/code/object/parameter.rb', line 183
def code_optional?
code_default.code_truthy?
end
|
#code_regular? ⇒ Boolean
151
152
153
|
# File 'lib/code/object/parameter.rb', line 151
def code_regular?
Boolean.new(code_get(:regular?))
end
|
#code_regular_splat? ⇒ Boolean
159
160
161
|
# File 'lib/code/object/parameter.rb', line 159
def code_regular_splat?
Boolean.new(code_get(:regular_splat?))
end
|
#code_required? ⇒ Boolean
179
180
181
|
# File 'lib/code/object/parameter.rb', line 179
def code_required?
code_default.code_falsy?
end
|
#code_spread? ⇒ Boolean
175
176
177
|
# File 'lib/code/object/parameter.rb', line 175
def code_spread?
Boolean.new(code_get(:spread?))
end
|
203
204
205
|
# File 'lib/code/object/parameter.rb', line 203
def keyword?
code_keyword?.truthy?
end
|
#keyword_splat? ⇒ Boolean
211
212
213
|
# File 'lib/code/object/parameter.rb', line 211
def keyword_splat?
code_keyword_splat?.truthy?
end
|
195
196
197
|
# File 'lib/code/object/parameter.rb', line 195
def optional?
code_optional?.truthy?
end
|
199
200
201
|
# File 'lib/code/object/parameter.rb', line 199
def regular?
code_regular?.truthy?
end
|
#regular_splat? ⇒ Boolean
207
208
209
|
# File 'lib/code/object/parameter.rb', line 207
def regular_splat?
code_regular_splat?.truthy?
end
|
191
192
193
|
# File 'lib/code/object/parameter.rb', line 191
def required?
code_required?.truthy?
end
|
215
216
217
|
# File 'lib/code/object/parameter.rb', line 215
def spread?
code_spread?.truthy?
end
|