I am having trouble translating this into Ruby.
Here is a piece of JavaScript that does exactly what I want to do:
function get_code(str){ return str
def get_code(str) str.sub(/^(Z_.*): .*/, '\1') end get_code('Z_foo: bar!') # => "Z_foo"