I want to use Proc, but I have no idea how to call the Proc in the array iterator. If possible, could you also suggest how to do this with MODULES?
esp. the part "result << (p.call(x))
def translate (str)
word = str.split(" ")
result = []
word.each do |x|
result << (p.call(x))
end
result.join(" ")
end
p = Proc.new do |single_word|
temp_array = single_word.split('')
num = ( single_word =~ /[aeiou]/)
num.times do
temp = temp_array.shift
temp_array << temp
end
temp_array << "ay"
temp_array.join("")
end
translate("best")
Not sure I understood your purposes correctly, but may be just:
Also this can be done with &block but I do not see why do you need proc or block in the example at all.