class CodeTools::AST::SingleBlockArg
Handles Rubinius.single_block_arg
Given the following code:
m { |x| ... }
In Ruby 1.8, this has the following semantics:
* x == nil if no values are yielded * x == val if one value is yielded * x == [p, q, r, ...] if more than one value is yielded * x == [a, b, c, ...] if one Array is yielded
In Ruby 1.9, this has the following semantics:
* x == nil if no values are yielded * x == val if one value is yielded * x == p if yield(p, q, r, ...) * x == [a, b, c, ...] if one Array is yielded
However, in Ruby 1.9, the Enumerator code manually implements the 1.8 block argument semantics. This transform exposes the VM instruction we use in 1.8 mode (cast_for_single_block_arg) so we can use it in 1.9 mode for Enumerator.
Public Class Methods
match?(line, receiver, name, arguments, privately)
click to toggle source
# File lib/rubinius/code/ast/transforms.rb, line 178 def self.match?(line, receiver, name, arguments, privately) match_send? receiver, :Rubinius, name, :single_block_arg end
Public Instance Methods
bytecode(g)
click to toggle source
# File lib/rubinius/code/ast/transforms.rb, line 182 def bytecode(g) if @arguments.splat? raise CompileError, "splat argument passed to single_block_arg" elsif @block raise CompileError, "block passed to single_block_arg" end pos(g) g.cast_for_single_block_arg end