Class: Melbourne::AST::IterArguments
- Defined in:
- lib/melbourne/ast/sends.rb
Overview
Arguments of a code block as in:
m { |arg| some }
Instance Attribute Summary collapse
-
#arguments ⇒ Object
The actual array of arguments.
-
#arity ⇒ Object
The number of arguments.
-
#optional ⇒ Object
The optional arguments.
-
#prelude ⇒ Object
TODO: document!.
-
#required_args ⇒ Object
(also: #total_args)
The required arguments.
-
#splat_index ⇒ Object
TODO: document!.
Attributes inherited from Node
Instance Method Summary collapse
-
#initialize(line, arguments) ⇒ IterArguments
constructor
A new instance of IterArguments.
-
#names ⇒ Object
TODO: document!.
Methods inherited from Node
Constructor Details
#initialize(line, arguments) ⇒ IterArguments
Returns a new instance of IterArguments.
270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 |
# File 'lib/melbourne/ast/sends.rb', line 270 def initialize(line, arguments) @line = line @optional = 0 @splat_index = -1 @required_args = 0 @splat = nil @block = nil array = [] case arguments when Fixnum @arity = 0 @prelude = nil when MAsgn arguments.iter_arguments if arguments.splat @splat = arguments.splat = arguments.splat.value @optional = 1 if arguments.left @prelude = :multi @arity = -(arguments.left.body.size + 1) @required_args = arguments.left.body.size else @prelude = :splat @arity = -1 end elsif arguments.left @prelude = :multi @arity = arguments.left.body.size @required_args = arguments.left.body.size else @prelude = :multi @arity = -1 end @block = arguments.block @arguments = arguments when nil @arity = -1 @splat_index = -2 # -2 means accept the splat, but don't store it anywhere @prelude = nil when BlockPass @arity = -1 @splat_index = -2 @prelude = nil @block = arguments else # Assignment @arguments = arguments @arity = 1 @required_args = 1 @prelude = :single end end |
Instance Attribute Details
#arguments ⇒ Object
The actual array of arguments
261 262 263 |
# File 'lib/melbourne/ast/sends.rb', line 261 def arguments @arguments end |
#arity ⇒ Object
The number of arguments
253 254 255 |
# File 'lib/melbourne/ast/sends.rb', line 253 def arity @arity end |
#optional ⇒ Object
The optional arguments
257 258 259 |
# File 'lib/melbourne/ast/sends.rb', line 257 def optional @optional end |
#prelude ⇒ Object
TODO: document!
249 250 251 |
# File 'lib/melbourne/ast/sends.rb', line 249 def prelude @prelude end |
#required_args ⇒ Object Also known as: total_args
The required arguments
268 269 270 |
# File 'lib/melbourne/ast/sends.rb', line 268 def required_args @required_args end |
#splat_index ⇒ Object
TODO: document!
264 265 266 |
# File 'lib/melbourne/ast/sends.rb', line 264 def splat_index @splat_index end |
Instance Method Details
#names ⇒ Object
TODO: document!
331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 |
# File 'lib/melbourne/ast/sends.rb', line 331 def names case @arguments when MAsgn if arguments = @arguments.left.body array = arguments.map { |x| x.name } else array = [] end if @arguments.splat.kind_of? SplatAssignment array << @arguments.splat.name end array when nil [] else [@arguments.name] end end |