module Enumerable
def map_select
reduce([]) { |accumulator, value|
new_value = yield value
accumulator << new_value if new_value
accumulator
}
end
end
p (1..10).map_select { |v| v.even? && v * 2 }
bW9kdWxlIEVudW1lcmFibGUKICBkZWYgbWFwX3NlbGVjdAogICAgcmVkdWNlKFtdKSB7IHxhY2N1bXVsYXRvciwgdmFsdWV8CiAgICAgIG5ld192YWx1ZSA9IHlpZWxkIHZhbHVlCiAgICAgIGFjY3VtdWxhdG9yIDw8IG5ld192YWx1ZSBpZiBuZXdfdmFsdWUKICAgICAgYWNjdW11bGF0b3IKICAgIH0gCSAgCQogIGVuZAplbmQKCnAgKDEuLjEwKS5tYXBfc2VsZWN0IHsgfHZ8IHYuZXZlbj8gJiYgdiAqIDIgfQ==