diskutil erasevolume HFS+ 'RAM Disk' `hdiutil attach -nomount ram://8388608`
where the number after ram:// is based on a number of 512 bytes sectors. That means the size in bytes has to be divided by 512. For example to calculate the size parameter for a volume with 4GiB the following formular is used:
(4 x 1024)/512=8388608