class BlockStorage
def initialize(&block)
@block = block
end
def execBlock(string)
if @block.respond_to? "call"
@block.call(string)
end
end
end
bs = BlockStorage.new() do |str|
arr = str.split(" ").reverse
arr2 = arr.map do |e|
puts "#{e}, #{arr.first}, #{arr.last}"
if e == arr.first
e.gsub(/\W$/, '').capitalize
elsif e == arr.last
e.downcase
else
e
end
end
arr2.join(" ")
end
puts bs.execBlock("Block coding is pretty darn cool.")
# Outputs 'Cool darn pretty is coding block'
puts bs.execBlock("It really streamlines the process.")
# Outputs 'Process the streamlines really it'
Better you than me, Mr. Hirschberg, better you than me...
ReplyDelete