Refactor layer selector to use Ruby constructs