There is a way to do this using Symbol#to_proc
, but it won't be any nicer than the (just fine) solution you already have, because it involves defining Array#^
.
class Array
def ^
raise("Not a two-element array") unless (self.length == 2)
raise("Array contains non-numeric values") unless (self.all? {|n| Integer === n })
return self[0] ^ self[1]
end
end
l.map(&:^)